1000char test
Dependencies: EthernetInterface HTTPClient mbed-rtos mbed
main.cpp
- Committer:
- karlovalentin
- Date:
- 2016-03-08
- Revision:
- 5:b4ceb49f67df
- Parent:
- 4:f99718565897
File content as of revision 5:b4ceb49f67df:
#include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" EthernetInterface eth; HTTPClient http; int main() { eth.init(); //Use DHCP eth.connect(); int a = 1; char str[4096]; int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 4096); /* //GET data printf("\nTrying to fetch page...\n"); int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128); 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()); }*/ //POST data HTTPMap map; HTTPText inText(str, 1024); map.put("data", "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890012345678901234567890123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345678900123456789012345678901234567890123456789012345"); //map.put("data", "{\"ts\":1457348930,\"dv\":\"karlotest1\",\"s00\":[94,-384,4138]}"); //map.put("data", "{\"ts\":1457071217,\"dv\":\"karlotest2a\",\"s00\":[140,-357,4142],\"s01\":[134,-354,4127],\"s02\":[140,-355,4136],\"s03\":[128,-354,4103],\"s04\":[137,-359,4184],\"s05\":[133,-357,4099],\"s06\":[139,-355,4116],\"s07\":[142,-348,4157],\"s08\":[137,-356,4131],\"s09\":[135,-355,4120],\"s10\":[138,-355,4123],\"s11\":[143,-349,4145],\"s12\":[141,-357,4121]}"); //map.put("data", "{\"ts\":1457071217,\"dv\":\"karlotest2b\",\"s00\":[140,-357,4142],\"s01\":[134,-354,4127],\"s02\":[140,-355,4136],\"s03\":[128,-354,4103],\"s04\":[137,-359,4184],\"s05\":[133,-357,4099],\"s06\":[139,-355,4116],\"s07\":[142,-348,4157],\"s08\":[137,-356,4131],\"s09\":[135,-355,4120],\"s10\":[138,-355,4123],\"s11\":[143,-349,4145],\"s12\":[141,-357,4121],\"s13\":[136,-353,4114],\"s14\":[142,-354,4158],\"s15\":[137,-355,4109],\"s16\":[138,-356,4144],\"s17\":[139,-357,4116],\"s18\":[136,-358,4137],\"s19\":[136,-356,4145],\"s20\":[136,-354,4133],\"s21\":[136,-358,4135],\"s22\":[139,-351,4130],\"s23\":[136,-361,4144],\"s24\":[136,-359,4131]}"); //map.put("hello", "world"); //map.put("test", "1234"); printf("\nTrying to post data...\n"); //ret = http.post("http://httpbin.org/post", map, &inText); while(a<100001){ ret = http.post("http://catcher.sensoresmx.info/index2.php", map, &inText); if (!ret) { printf("Executed POST 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()); } a++; } /* //PUT data strcpy(str, "This is a PUT test!"); HTTPText outText(str); //HTTPText inText(str, 512); printf("\nTrying to put resource...\n"); ret = http.put("http://httpbin.org/put", outText, &inText); if (!ret) { printf("Executed PUT 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()); } */ //DELETE data //HTTPText inText(str, 512); /* printf("\nTrying to delete resource...\n"); ret = http.del("http://httpbin.org/delete", &inText); if (!ret) { printf("Executed DELETE 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()); }*/ eth.disconnect(); /*while(1) { }*/ }