Francois Berder / Mbed 2 deprecated HTTPSClientExample

Dependencies:   EthernetInterface3 HTTPSClient TLS_axTLS mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
feb11
Date:
Thu Sep 05 10:36:51 2013 +0000
Parent:
0:d6829ea0374e
Child:
2:e3807a060fa5
Commit message:
retrieve web page from twitter instead of mbed.org and output is written in a file instead of the terminal

Changed in this revision

HTTPSClient.lib Show annotated file Show diff for this revision Revisions of this file
TLS.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPSClient.lib	Wed Sep 04 13:40:42 2013 +0000
+++ b/HTTPSClient.lib	Thu Sep 05 10:36:51 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/feb11/code/HTTPSClient/#ab9011f6ede5
+http://mbed.org/users/feb11/code/HTTPSClient/#95f92eed4e09
--- a/TLS.lib	Wed Sep 04 13:40:42 2013 +0000
+++ b/TLS.lib	Thu Sep 05 10:36:51 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/feb11/code/TLS/#303a0d37b5e0
+http://mbed.org/users/feb11/code/TLS/#26cd1cceb71a
--- a/main.cpp	Wed Sep 04 13:40:42 2013 +0000
+++ b/main.cpp	Thu Sep 05 10:36:51 2013 +0000
@@ -3,12 +3,13 @@
 #include "CertificateManager.h"
 #include "HTTPSClient.h"
 
-const char host[] = "mbed.org";
-const char request[] = "/";
+const char host[] = "twitter.com";
+const char request[] = "https://twitter.com/";
 LocalFileSystem local("local");
 
 int main()
 {
+    set_time(1378370406);
     EthernetInterface eth;
     if(eth.init() || eth.connect())
     {
@@ -21,7 +22,6 @@
     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");
@@ -34,6 +34,8 @@
         printf("Failed to connect to %s\n", host);
         return -1;
     }
+    printf("Connected to %s !\n", host);
+    CertificateManager::clear();
     
     char buffer[256];
     int bufferLength = sizeof(buffer)-1;
@@ -45,8 +47,13 @@
         return -1;
     }
     
-    buffer[read] ='\0';
-    printf("%s", buffer);
+    FILE *fp = fopen("/local/index.htm", "w");
+    if(fp == NULL)
+    {
+        printf("Failed to open file index.htm\n");
+        return -1;
+    }
+    fwrite(buffer, 1, read, fp);
     int totalRead = read;
     while(totalRead < header.getBodyLength())
     {
@@ -54,10 +61,15 @@
             bufferLength = header.getBodyLength() - totalRead;
         
         read = client.get("", NULL, buffer, bufferLength);
-        buffer[read] ='\0';
-        printf("%s", buffer);
+        if(read < 0)
+        {
+            printf("Error while getting data from %s\n", host);
+            return -1;
+        }
+         fwrite(buffer, 1, read, fp);
         totalRead += read;
     }
+    fclose(fp);
     
     printf("Disconnecting from %s\n", host);
     client.disconnect();