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 mbed-rtos mbed
Fork of HTTP_GET by
Diff: main.cpp
- Revision:
- 1:2e29a33cd918
- Parent:
- 0:fb5060c39dd1
- Child:
- 2:c9e058ee6f87
diff -r fb5060c39dd1 -r 2e29a33cd918 main.cpp
--- a/main.cpp Sun Feb 02 18:16:51 2014 +0000
+++ b/main.cpp Sat Jan 17 14:11:01 2015 +0000
@@ -1,30 +1,87 @@
+/** Beispiel fuer Verwendung der HTTP Methoden (GET, POST, PUT, DELETE)
+ *
+ * Braucht ein Board mit Ethernet
+ */
#include "mbed.h"
#include "HTTPClient.h"
+#include "HTTPText.h"
#include "EthernetInterface.h"
Serial pc(USBTX, USBRX);
EthernetInterface eth;
HTTPClient http;
-char message[2000];
+char message[6000];
+char str[512];
DigitalOut myled(LED1);
-int main() {
- pc.baud(460800);
+int main()
+{
+ pc.baud(9600);
printf("HTTP Client - Build " __DATE__ " - " __TIME__ "\r\n");
eth.init();
eth.connect();
- while(1) {
+ while(1)
+ {
myled = 1;
- int ret = http.get("http://mbed.org/media/uploads/mbed_official/hello.txt", message, sizeof(message));
- if (!ret) {
+ printf( "GET http://developer.mbed.org/media/uploads/mbed_official/hello.txt\n" );
+ //int ret = http.get("https://raw.githubusercontent.com/mc-b/microHOME/master/README.md", message, sizeof(message));
+ int ret = http.get("http://developer.mbed.org/media/uploads/mbed_official/hello.txt", message, sizeof(message));
+ if ( !ret )
+ {
printf("Success - read %d characters.\r\n", strlen(message));
printf("%s\r\n", message);
}
+ else
+ printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+
myled = 0;
+
+ //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());
+ }
+
wait(10);
+ break;
}
// eth.disconnect();
}
