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:
- 1:ff73b1545aaa
- Parent:
- 0:d6829ea0374e
- Child:
- 2:e3807a060fa5
diff -r d6829ea0374e -r ff73b1545aaa main.cpp
--- 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();