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 1:77c616a1ab54 1 /* HTTPPoster.h */
va009039 0:fcd577a3925b 2 #ifndef HTTP_POSTER_H
va009039 0:fcd577a3925b 3 #define HTTP_POSTER_H
va009039 1:77c616a1ab54 4
va009039 1:77c616a1ab54 5 #include "../IHTTPData.h"
va009039 1:77c616a1ab54 6
va009039 0:fcd577a3925b 7 #include "mbed.h"
va009039 1:77c616a1ab54 8 #include <string>
va009039 0:fcd577a3925b 9 #include <vector>
va009039 0:fcd577a3925b 10
va009039 0:fcd577a3925b 11 /** HTTPPoster HTTP Client data container for form(multipart/form-data)
va009039 0:fcd577a3925b 12 *
va009039 0:fcd577a3925b 13 *@code
va009039 0:fcd577a3925b 14 *HTTPClient client;
va009039 0:fcd577a3925b 15 *HTTPPoster data;
va009039 0:fcd577a3925b 16 *data.addFile("image", "/local/image.jpg");
va009039 0:fcd577a3925b 17 *data.add("title", "hello");
va009039 0:fcd577a3925b 18 *string url = "http://va009039.appspot.com/mbed/upload/";
va009039 0:fcd577a3925b 19 *HTTPResult r = client.post(url.c_str(), data, NULL);
va009039 0:fcd577a3925b 20 *printf("result:%d HTTPResponseCode: %d\n", r, client.getHTTPResponseCode());
va009039 0:fcd577a3925b 21 *@endcode
va009039 0:fcd577a3925b 22 */
va009039 0:fcd577a3925b 23
va009039 0:fcd577a3925b 24 struct stpost {
va009039 0:fcd577a3925b 25 bool file;
va009039 0:fcd577a3925b 26 string head;
va009039 0:fcd577a3925b 27 string value;
va009039 0:fcd577a3925b 28 int length;
va009039 0:fcd577a3925b 29 };
va009039 0:fcd577a3925b 30
va009039 0:fcd577a3925b 31 ///HTTPPoster HTTP Client data container for form(multipart/form-data)
va009039 1:77c616a1ab54 32 class HTTPPoster : public IHTTPDataOut
va009039 0:fcd577a3925b 33 {
va009039 0:fcd577a3925b 34 public:
va009039 1:77c616a1ab54 35 ///Instantiates the object.
va009039 1:77c616a1ab54 36 HTTPPoster();
va009039 1:77c616a1ab54 37 ///put file
va009039 1:77c616a1ab54 38 bool addFile(const char* name, const char* path);
va009039 1:77c616a1ab54 39 ///put param
va009039 1:77c616a1ab54 40 bool add(const char* name, const char* value);
va009039 0:fcd577a3925b 41
va009039 1:77c616a1ab54 42 virtual ~HTTPPoster();
va009039 0:fcd577a3925b 43 protected:
va009039 1:77c616a1ab54 44 //IHTTPDataOut
va009039 1:77c616a1ab54 45 virtual int read(char* buf, size_t len, size_t* pReadLen);
va009039 1:77c616a1ab54 46 virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
va009039 1:77c616a1ab54 47 virtual bool getIsChunked(); //For Transfer-Encoding header
va009039 1:77c616a1ab54 48 virtual size_t getDataLen(); //For Content-Length header
va009039 1:77c616a1ab54 49
va009039 0:fcd577a3925b 50 private:
va009039 0:fcd577a3925b 51 int m_seq;
va009039 0:fcd577a3925b 52 int m_cur;
va009039 0:fcd577a3925b 53 int m_pos;
va009039 0:fcd577a3925b 54 vector <stpost> m_post_data;
va009039 0:fcd577a3925b 55 FILE* m_fp;
va009039 0:fcd577a3925b 56 int m_len;
va009039 0:fcd577a3925b 57 int m_send_len;
va009039 0:fcd577a3925b 58 string m_buf;
va009039 0:fcd577a3925b 59 string m_ContentType;
va009039 0:fcd577a3925b 60 char* m_boundary;
va009039 0:fcd577a3925b 61 };
va009039 1:77c616a1ab54 62
va009039 1:77c616a1ab54 63 #endif // HTTP_POSTER_H