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
Diff: source/main-https.cpp
- Revision:
- 32:5fa61ebc2689
- Parent:
- 31:66704f6f17c5
- Child:
- 34:7da6cfc032fc
--- a/source/main-https.cpp Tue Mar 27 11:57:33 2018 +0200
+++ b/source/main-https.cpp Tue Oct 30 11:07:46 2018 +0800
@@ -1,13 +1,16 @@
+#define MBED_CONF_MBED_TRACE_ENABLE 1
+
#include "select-demo.h"
#if DEMO == DEMO_HTTPS
#include "mbed.h"
-#include "easy-connect.h"
+#include "mbed_trace.h"
#include "https_request.h"
+#include "network-helper.h"
/* List of trusted root CA certificates
- * currently two: GlobalSign, the CA for developer.mbed.org and Let's Encrypt, the CA for httpbin.org
+ * currently two: GlobalSign, the CA for os.mbed.com and Let's Encrypt, the CA for httpbin.org
*
* To add more root certificates, just concatenate them.
*/
@@ -61,27 +64,29 @@
"-----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() {
- NetworkInterface* network = easy_connect(true);
+ NetworkInterface* network = connect_to_default_network_interface();
if (!network) {
+ printf("Cannot connect to the network, see serial output\n");
return 1;
}
- // GET request to developer.mbed.org
+ 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) {
@@ -99,7 +104,6 @@
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\"}";