HTTP Client data container for form(multipart/form-data)
Dependencies: mbed EthernetInterface HTTPClient mbed-rtos
Diff: file_upload.cpp
- Revision:
- 1:77c616a1ab54
- Parent:
- 0:fcd577a3925b
--- a/file_upload.cpp Thu May 31 10:32:39 2012 +0000 +++ b/file_upload.cpp Tue Aug 28 14:39:29 2012 +0000 @@ -1,29 +1,35 @@ #include "mbed.h" -#include "EthernetNetIf.h" +#include "EthernetInterface.h" #include "HTTPClient.h" #include "HTTPPoster.h" +#include "HTTPNull.h" + +Serial pc(USBTX, USBRX); LocalFileSystem local("local"); -Serial pc(USBTX, USBRX); - -EthernetNetIf eth; +EthernetInterface eth; +HTTPClient http; int main() { pc.baud(921600); - - int ethErr = eth.setup(); - if(ethErr) {printf("Error %d in setup.\n", ethErr); exit(1);} + printf("%s\n", __FILE__); - HTTPClient client; + eth.init(); //Use DHCP + eth.connect(); + HTTPPoster data; - data.addFile("image", "/local/image.jpg"); + HTTPNull text_null; + data.addFile("image", "/local/image1.jpg"); data.add("title", "hello"); string url = "http://va009039.appspot.com/mbed/upload/"; - HTTPResult r = client.post(url.c_str(), data, NULL); - - printf("result:%d HTTPResponseCode: %d\n", r, client.getHTTPResponseCode()); + HTTPResult ret = http.post(url.c_str(), data, &text_null); + if (!ret) { + printf("Executed POST successfully\n"); + } else { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } exit(1); }