Simple HTTP Client Example with HTTPClient class
Dependencies: HTTPClient mbed-rtos mbed-src
main.cpp
- Committer:
- takashikojo
- Date:
- 2014-12-01
- Revision:
- 1:24d373f4f0ea
- Parent:
- 0:880477b153ac
- Child:
- 2:caac3459ca52
File content as of revision 1:24d373f4f0ea:
#include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" #define HOST "192.168.1.12" EthernetInterface eth; HTTPClient http; char str[1024*20]; void main_body(void const *av) { char url[100] ; int ret ; //GET data printf("\nTrying to fetch page...\n"); sprintf(url, "http://%s/", HOST) ; printf("url=%s\n",url) ; ret = http.get(url, str, sizeof(str)-1,16); if (!ret) { printf("Page fetched successfully - read %d characters\n", strlen(str)); printf("Result: %s\n", str); } else { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); } } int main() { int ret ; void *av ; printf("HTTP Client Starting,...\n") ; ret = eth.init(); //Use DHCP while(1) { ret = eth.connect(); if(ret == 0)break ; } printf("IP = %s\n", eth.getIPAddress()); #define STACK_SIZE 20000 //Thread t(main_body, NULL, osPriorityNormal, STACK_SIZE); main_body(av) ; eth.disconnect(); while(1) { } }