Connect to twitter.com and copies this webpage to a file.
Dependencies: EthernetInterface3 HTTPSClient TLS_axTLS mbed-rtos mbed
This example shows how to use the HTTPSClient library by copying the content of this webpage to a file. Before running this program, you must download these certificates and copy them to the mbed. After running this program, a file called index.htm has been created and you can open it with your favorite browser to display the webpage the mbed have just downloaded.
Revision 0:d6829ea0374e, committed 2013-09-04
- Comitter:
- feb11
- Date:
- Wed Sep 04 13:40:42 2013 +0000
- Child:
- 1:ff73b1545aaa
- Commit message:
- initial import
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Wed Sep 04 13:40:42 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/feb11/code/EthernetInterface3/#84169365bdfc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPSClient.lib Wed Sep 04 13:40:42 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/feb11/code/HTTPSClient/#ab9011f6ede5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TLS.lib Wed Sep 04 13:40:42 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/feb11/code/TLS/#303a0d37b5e0
--- /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; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed Sep 04 13:40:42 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#869ef732a8a2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 04 13:40:42 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9c8f0e3462fb \ No newline at end of file