HTTP Client data container for form(multipart/form-data)

Dependencies:   mbed EthernetInterface HTTPClient mbed-rtos

Committer:
va009039
Date:
Tue Aug 28 14:39:29 2012 +0000
Revision:
1:77c616a1ab54
Parent:
0:fcd577a3925b
update to using new HTTPClient

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:fcd577a3925b 1 #include "mbed.h"
va009039 1:77c616a1ab54 2 #include "EthernetInterface.h"
va009039 0:fcd577a3925b 3 #include "HTTPClient.h"
va009039 0:fcd577a3925b 4 #include "HTTPPoster.h"
va009039 1:77c616a1ab54 5 #include "HTTPNull.h"
va009039 1:77c616a1ab54 6
va009039 1:77c616a1ab54 7 Serial pc(USBTX, USBRX);
va009039 0:fcd577a3925b 8
va009039 0:fcd577a3925b 9 LocalFileSystem local("local");
va009039 0:fcd577a3925b 10
va009039 1:77c616a1ab54 11 EthernetInterface eth;
va009039 1:77c616a1ab54 12 HTTPClient http;
va009039 0:fcd577a3925b 13
va009039 0:fcd577a3925b 14 int main() {
va009039 0:fcd577a3925b 15 pc.baud(921600);
va009039 1:77c616a1ab54 16 printf("%s\n", __FILE__);
va009039 0:fcd577a3925b 17
va009039 1:77c616a1ab54 18 eth.init(); //Use DHCP
va009039 1:77c616a1ab54 19 eth.connect();
va009039 1:77c616a1ab54 20
va009039 0:fcd577a3925b 21 HTTPPoster data;
va009039 1:77c616a1ab54 22 HTTPNull text_null;
va009039 1:77c616a1ab54 23 data.addFile("image", "/local/image1.jpg");
va009039 0:fcd577a3925b 24 data.add("title", "hello");
va009039 0:fcd577a3925b 25 string url = "http://va009039.appspot.com/mbed/upload/";
va009039 0:fcd577a3925b 26
va009039 1:77c616a1ab54 27 HTTPResult ret = http.post(url.c_str(), data, &text_null);
va009039 1:77c616a1ab54 28 if (!ret) {
va009039 1:77c616a1ab54 29 printf("Executed POST successfully\n");
va009039 1:77c616a1ab54 30 } else {
va009039 1:77c616a1ab54 31 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
va009039 1:77c616a1ab54 32 }
va009039 0:fcd577a3925b 33
va009039 0:fcd577a3925b 34 exit(1);
va009039 0:fcd577a3925b 35 }