An example of request Http POST with X_NUCLEO_IDW01M1
Dependencies: NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed
Fork of TestUpload by
Revision 12:6dc4d1fe7604, committed 2017-02-01
- Comitter:
- erbistiandrea
- Date:
- Wed Feb 01 16:20:20 2017 +0000
- Parent:
- 11:0138f6cb216a
- Commit message:
- An example of request HTTP POST with X_NUCLEO_IDW01M1
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jan 13 14:05:16 2017 +0000
+++ b/main.cpp Wed Feb 01 16:20:20 2017 +0000
@@ -32,8 +32,8 @@
TCPSocket socket;
int main() {
- char* ssid = "STM";
- char* seckey = "STMDemo";
+ char* ssid = "fablab_guest";
+ char* seckey = "veronafablab";
pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
pc.printf("\r\nconnecting to AP\r\n");
@@ -49,15 +49,29 @@
const char *mac = spwf.get_mac_address();
pc.printf("\r\nIP Address is: %s\r\n", (ip) ? ip : "No IP");
- pc.printf("\r\nMAC Address is: %s\r\n", (mac) ? mac : "No MAC");
-
+ pc.printf("MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
+
+
socket.open(&spwf);
- socket.connect("developer.mbed.org", 80);
-
+ socket.connect("fabio.infosistem.it", 80);
+ char url[] = "http://fabio.infosistem.it/post.php";
+ char host[] = "fabio.infosistem.it";
+ char path[] = "/post.php";
+ char meth[] = "POST"; //http method ('POST', 'GET', 'PUT', 'DELETE')
+ //char key[] = "Hello";
+ //char value[] = "World";
+ // Body of the message
+ char data[] = "Hello=World";
+ //snprintf(data, sizeof(data), "%s=%s", key, value);
+ printf("\r\n%s\r\n", data);
+ char type[] = "Content-Type: application/x-www-form-urlencoded";
+ char length[32];
+ snprintf(length, sizeof(length), "Content-Length: %s", sizeof(data));
// Send a simple http request
- char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n";
+ char sbuffer[256];
+ snprintf(sbuffer,sizeof(sbuffer),"%s %s HTTP/1.1\r\n\%s\r\nHost: %s\r\n%s\r\n\r\n%s\r\n", meth, path, type, host, length, data);
int scount = socket.send(sbuffer, sizeof sbuffer);
- printf("sent %d [%.*s]\r\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
+ printf("sent %d\r\n%s", scount, sbuffer);
// Recieve a simple http response and print out the response line
char rbuffer[64];
