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

Dependencies:   mbed EthernetInterface HTTPClient mbed-rtos

Committer:
va009039
Date:
Thu May 31 10:32:39 2012 +0000
Revision:
0:fcd577a3925b
Child:
1:77c616a1ab54

        

Who changed what in which revision?

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