diff options
author | Jun Wako <wakojun@gmail.com> | 2015-04-24 16:26:14 +0900 |
---|---|---|
committer | Jun Wako <wakojun@gmail.com> | 2015-04-24 16:26:14 +0900 |
commit | a3d96d3aa96318d339a67de1085e0ae495d57c84 (patch) | |
tree | db85c16d03b52399d6c109eda7ea0341a0de0b1d /tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/httptest.cpp | |
parent | 1d5bac21dc6f1425b8ef4bbe7935330c37c3a93e (diff) | |
parent | 1fe4406f374291ab2e86e95a97341fd9c475fcb8 (diff) |
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
Diffstat (limited to 'tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/httptest.cpp')
-rw-r--r-- | tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/httptest.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/httptest.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/httptest.cpp new file mode 100644 index 0000000000..e3db1c826a --- /dev/null +++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/net/cellular/http/common/httptest.cpp @@ -0,0 +1,58 @@ +#include "mbed.h" +#include "CellularModem.h" +#include "HTTPClient.h" +#include "httptest.h" + +int httptest(CellularModem& modem, const char* apn, const char* username, const char* password) +{ + printf("Connecting...\n"); + + HTTPClient http; + char str[512]; + + modem.power(true); + Thread::wait(1000); + int ret = modem.connect(apn, username, password); + if(ret) + { + printf("Could not connect\n"); + return false; + } + + //GET data + printf("Trying to fetch page...\n"); + ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128); + if (!ret) + { + printf("Page fetched 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()); + modem.disconnect(); + return false; + } + + //POST data + HTTPMap map; + HTTPText text(str, 512); + map.put("Hello", "World"); + map.put("test", "1234"); + printf("Trying to post data...\n"); + ret = http.post("http://httpbin.org/post", map, &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()); + modem.disconnect(); + return false; + } + + modem.disconnect(); + return true; +} |