Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-http HTS221
Diff: source/main-https.cpp
- Branch:
- mbed-os-5.10
- Revision:
- 31:66704f6f17c5
- Parent:
- 30:4825e4f38844
- Child:
- 34:7da6cfc032fc
--- a/source/main-https.cpp Mon Oct 29 14:34:43 2018 +0800
+++ b/source/main-https.cpp Tue Oct 30 11:07:10 2018 +0800
@@ -1,8 +1,11 @@
+#define MBED_CONF_MBED_TRACE_ENABLE 1
+
#include "select-demo.h"
#if DEMO == DEMO_HTTPS
#include "mbed.h"
+#include "mbed_trace.h"
#include "https_request.h"
#include "network-helper.h"
@@ -61,13 +64,13 @@
"-----END CERTIFICATE-----\n";
void dump_response(HttpResponse* res) {
- mbedtls_printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
+ printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
- mbedtls_printf("Headers:\n");
+ printf("Headers:\n");
for (size_t ix = 0; ix < res->get_headers_length(); ix++) {
- mbedtls_printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str());
+ printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str());
}
- mbedtls_printf("\nBody (%d bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
+ printf("\nBody (%lu bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
}
int main() {
@@ -77,17 +80,18 @@
return 1;
}
+ mbed_trace_init();
+
// GET request to os.mbed.com
{
printf("\n----- HTTPS GET request -----\n");
HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, "https://os.mbed.com/media/uploads/mbed_official/hello.txt");
- get_req->set_debug(true);
HttpResponse* get_res = get_req->send();
if (!get_res) {
printf("HttpRequest failed (error code %d)\n", get_req->get_error());
- goto demo2;
+ return 1;
}
printf("\n----- HTTPS GET response -----\n");
dump_response(get_res);
@@ -95,13 +99,11 @@
delete get_req;
}
-demo2:
// POST request to httpbin.org
{
printf("\n----- HTTPS POST request -----\n");
HttpsRequest* post_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_POST, "https://httpbin.org/post");
- post_req->set_debug(true);
post_req->set_header("Content-Type", "application/json");
const char body[] = "{\"hello\":\"world\"}";