Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface TMP175 mbed-rtos mbed
Fork of 2-07-04-Uebung by
Diff: main.cpp
- Revision:
- 5:13c63366d788
- Parent:
- 3:aad64a4b6ff6
- Child:
- 6:48a4698a3416
--- a/main.cpp Wed May 27 08:11:32 2015 +0000 +++ b/main.cpp Wed May 27 08:16:40 2015 +0000 @@ -1,5 +1,5 @@ -/** Beispiel HTTP GET - */ +/** HTTP POST Beispiel +*/ #include "mbed.h" #include "HTTPClient.h" #include "HTTPText.h" @@ -9,31 +9,42 @@ // HTTPClient Hilfsklasse HTTPClient http; // I/O Buffer -char message[6000]; +char str[512]; DigitalOut myled(LED1); int main() { - printf("HTTP Client - GET\n"); + printf("HTTP Client - POST\n"); eth.init(); eth.connect(); while(1) { myled = 1; - int ret = http.get("http://developer.mbed.org/media/uploads/mbed_official/hello.txt", message, sizeof(message)); - if ( !ret ) + + // Hilfsklasse um die Response vom Server zu formatieren + HTTPText inText(str, 512); + + // MAP (Argument=Wert) + HTTPMap map; + map.put("DigitalOut", "LED1"); + map.put("write", "1"); + + int ret = http.post("http://httpbin.org/post", map, &inText); + if ( ! ret ) { - printf("Success - read %d characters.\r\n", strlen(message)); - printf("%s\r\n", message); + 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()); } - else - printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); myled = 0; wait(10); } - eth.disconnect(); -} + //eth.disconnect(); +} \ No newline at end of file