http

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
planglois
Date:
Fri Sep 12 17:14:15 2014 +0000
Child:
1:d29e4c5d19bb
Commit message:
test

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Fri Sep 12 17:14:15 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#5887ae6c0c2c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Fri Sep 12 17:14:15 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#277279a1891e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Sep 12 17:14:15 2014 +0000
@@ -0,0 +1,79 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "HTTPClient.h"
+ 
+EthernetInterface eth;
+HTTPClient http;
+char str[512];
+ 
+int main() 
+{
+    eth.init(); //Use DHCP
+ 
+    eth.connect();
+    
+    //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, 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, 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) {}
+}
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Sep 12 17:14:15 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#bd07334df5b1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Sep 12 17:14:15 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file