Test HTTPClient over WiFi

Dependencies:   HTTPClient WiflyInterface mbed

Revision:
0:fac87adbcc27
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 17 21:23:37 2014 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "WiflyInterface.h"
+#include "HTTPClient.h"
+
+// WiFi configuration (edit this)
+#define WIFI_SSID               ""
+#define WIFI_SECURITY           WPA    // NONE, WEP_128 or WPA
+#define WIFI_PASSWORD           ""
+             
+// ****************************************************************************
+// WiFi initialization
+
+static WiflyInterface wifly(p9, p10, p30, p29, WIFI_SSID, WIFI_PASSWORD, WIFI_SECURITY);
+
+int main(void)
+{
+    HTTPClient http;
+    char str[512];
+    
+    printf("\n******************************************************************\n");
+    wifly.init();
+    if(wifly.connect() == 0)
+        printf("Connect OK\n\r");
+    printf("IP Address is %s\n\r", wifly.getIPAddress());
+    
+    //POST data
+    HTTPText text(str, 512);
+    // LONG AND SHORT REQUESTS
+    HTTPText data("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n");
+    //HTTPText data("23123123lala\n");
+    printf("Trying to post data...\n");
+    int ret = http.post("http://vps.eluaproject.net:8888/", data, &text);
+
+    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());
+    }
+    
+    wifly.disconnect();
+    return 0;
+}