3 #include "EthernetInterface.h"
4 #include "HTTPClient.h"
8 const int BUFFER_SIZE = 512;
12 MBED_HOSTTEST_TIMEOUT(15);
13 MBED_HOSTTEST_SELECT(default_auto);
14 MBED_HOSTTEST_DESCRIPTION(HTTP client hello world);
15 MBED_HOSTTEST_START("NET_7");
17 char http_request_buffer[BUFFER_SIZE + 1] = {0};
19 EthernetInterface eth;
20 eth.init(); //Use DHCP
26 const char *url_hello_txt = "http://developer.mbed.org/media/uploads/donatien/hello.txt";
27 printf("HTTP_GET: Trying to fetch page '%s'...\r\n", url_hello_txt);
28 HTTPResult ret = http.get(url_hello_txt, http_request_buffer, BUFFER_SIZE);
30 printf("HTTP_GET: Read %d chars: '%s' ... [OK]\r\n", strlen(http_request_buffer), http_request_buffer);
32 printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode());
36 if (result == false) {
38 MBED_HOSTTEST_RESULT(false);
45 const char *url_httpbin_post = "http://httpbin.org/post";
46 HTTPText text(http_request_buffer, BUFFER_SIZE);
48 map.put("Hello", "World");
49 map.put("test", "1234");
50 printf("HTTP_POST: Trying to post data to '%s' ...\r\n", url_httpbin_post);
51 HTTPResult ret = http.post(url_httpbin_post, map, &text);
53 printf("HTTP_POST: Read %d chars ... [OK]\r\n", strlen(http_request_buffer));
54 printf("HTTP_POST: %s\r\n", http_request_buffer);
56 printf("HTTP_GET: Error(%d). HTTP error(%d) ... [FAIL]\r\n", ret, http.getHTTPResponseCode());
60 if (result == false) {
62 MBED_HOSTTEST_RESULT(false);
66 MBED_HOSTTEST_RESULT(true);