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.
HttpClientStreamingExample.cpp
- Committer:
- donatien
- Date:
- 2010-05-27
- Revision:
- 0:b6b9d1b95cc7
- Child:
- 1:0e4f1cc78052
File content as of revision 0:b6b9d1b95cc7:
#include "mbed.h" #include "EthernetNetIf.h" #include "HttpClient.h" EthernetNetIf eth; HttpClient http; HttpResult result; bool completed = false; void request_callback(HttpResult r) { result = r; printf("\r\n-----Err %d-----\r\n", r); completed = true; } Serial pc(USBTX, USBRX); int main() { pc.baud(115200); printf("Start\n"); printf("\r\nSetting up...\r\n"); EthernetErr ethErr = eth.setup(); if(ethErr) { printf("Error %d in setup.\n", ethErr); return -1; } printf("\r\nSetup OK\r\n"); HttpStream stream; char BigBuf[1024 + 1] = {0}; stream.readNext((byte*)BigBuf, 1024); HttpResult r = http.get("http://mbed.org/", &stream, request_callback); while(!completed) { Net::poll(); if(stream.readable()) { BigBuf[stream.readLen()+1] = 0; printf("%s",BigBuf); stream.readNext((byte*)BigBuf, 1024); } } printf("\r\n--------------\r\n"); if(result == HTTP_OK) { printf("Read completely\n"); } else { printf("Error %d\n", r); } while(1) { } return 0; }