Update library (02 Feb 2015)
Dependencies: EthernetInterface HTTPClient mbed-rtos mbed
Fork of HTTPClient_HelloWorld by
Diff: main.cpp
- Revision:
- 6:b6f680d83b3c
- Parent:
- 5:f2c6eeb33c97
diff -r f2c6eeb33c97 -r b6f680d83b3c main.cpp
--- a/main.cpp Sun Feb 01 15:30:08 2015 +0000
+++ b/main.cpp Sun Feb 01 15:43:37 2015 +0000
@@ -26,56 +26,68 @@
}
- //GET data
- printf("\nTrying to fetch page...\n");
- 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());
+ // GET data
+ {
+ printf("\nTrying to GET request...\n");
+ ret = http.get("http://developer.mbed.org/media/uploads/donatien/hello.txt", str, sizeof(str));
+ 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, sizeof(str));
+ map.put("Hello", "World");
+ map.put("test", "1234");
+
+ printf("\nTrying to POST request...\n");
+ ret = http.post("http://httpbin.org/post", 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());
+ }
}
- //POST data
- HTTPMap map;
- HTTPText inText(str, 512);
- map.put("Hello", "World");
- map.put("test", "1234");
- printf("\nTrying to post data...\n");
- ret = http.post("http://httpbin.org/post", 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());
+ // PUT data
+ {
+ strcpy(str, "This is a PUT test!");
+ HTTPText outText(str);
+ HTTPText inText(str, sizeof(str));
+
+ printf("\nTrying to PUT request...\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());
+ }
}
- //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, sizeof(str));
- //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());
+ printf("\nTrying to DELETE request...\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());
+ }
}
printf("\n");
+
ret = eth.disconnect();
if (!ret) {
printf("Disconnected\n");
ban4jp -
