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: EthernetInterface3 HTTPSClient TLS_axTLS mbed-rtos mbed
Diff: main.cpp
- Revision:
- 0:d6829ea0374e
- Child:
- 1:ff73b1545aaa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Sep 04 13:40:42 2013 +0000
@@ -0,0 +1,67 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "CertificateManager.h"
+#include "HTTPSClient.h"
+
+const char host[] = "mbed.org";
+const char request[] = "/";
+LocalFileSystem local("local");
+
+int main()
+{
+ EthernetInterface eth;
+ if(eth.init() || eth.connect())
+ {
+ printf("Error with EthernetInterface\n\r");
+ return -1;
+ }
+
+ printf("IP address is %s\n\r", eth.getIPAddress());
+
+ CertificateManager::add("/local/cert1.der");
+ CertificateManager::add("/local/cert2.der");
+ CertificateManager::add("/local/cert3.der");
+ CertificateManager::add("/local/cert4.der");
+ if(!CertificateManager::load(true))
+ {
+ printf("Failed to load certificates\n");
+ return -1;
+ }
+
+ HTTPSClient client;
+ if(!client.connect(host))
+ {
+ printf("Failed to connect to %s\n", host);
+ return -1;
+ }
+
+ char buffer[256];
+ int bufferLength = sizeof(buffer)-1;
+ HTTPHeader header;
+ int read = client.get(request, &header, buffer, bufferLength);
+ if(header.getStatus() != HTTP_OK || read < 0)
+ {
+ printf("Failed sending GET request : %s to %s", request, host);
+ return -1;
+ }
+
+ buffer[read] ='\0';
+ printf("%s", buffer);
+ int totalRead = read;
+ while(totalRead < header.getBodyLength())
+ {
+ if(bufferLength > header.getBodyLength() - totalRead)
+ bufferLength = header.getBodyLength() - totalRead;
+
+ read = client.get("", NULL, buffer, bufferLength);
+ buffer[read] ='\0';
+ printf("%s", buffer);
+ totalRead += read;
+ }
+
+ printf("Disconnecting from %s\n", host);
+ client.disconnect();
+ eth.disconnect();
+
+ return 0;
+}