A version of LWIP, provided for backwards compatibility.
Dependents: AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more
HTTPClient.h
00001 #ifndef HTTPCLIENT_H 00002 #define HTTPCLIENT_H 00003 00004 #include "TCPConnection.h" 00005 #include "NetServer.h" 00006 00007 class HTTPClient : public TCPConnection { 00008 public: 00009 /** 00010 * @brief Default constructor. 00011 * Creates an HTTPClient object. You might want to initialise the network server befor. 00012 * If you dont do it it will be happen by the first post or get request you make. 00013 */ 00014 HTTPClient() : TCPConnection(), _auth(NULL), _timeout(0), _data(NULL), _headerfields(NULL) {} 00015 00016 /** 00017 * @brief Default destructor 00018 * Just to have one. In case of... 00019 */ 00020 virtual ~HTTPClient() { 00021 if(_auth) { 00022 delete _auth; 00023 _auth = NULL; 00024 } 00025 } 00026 00027 /** 00028 * @brief Add header additional Information to the next post or get requests. 00029 * Somtimes it is useful to add further header information. For example an auth field. 00030 * Each time you call this function it will be replace the header fields given by an 00031 * prior call. 00032 * 00033 * It will not free your data. 00034 */ 00035 void headers(const char *fields); 00036 00037 00038 void auth(const char *user, const char *password); 00039 00040 /** 00041 * @brief A simple get-request just insert the url. 00042 * But if you want you can get the result back as a string. 00043 * Sometimes you want get a large result, more than 64 Bytes 00044 * than define your size. 00045 * 00046 * @param url The requested URL. 00047 * @param result The answere to your request, by default you have not to take it. 00048 * But if you want it, it has a default length from 64 Bytes. 00049 * @param rsize The maximum size of your result. By default 64 Bytes. 00050 * @result The length of your demanted result or 1 if the request is succssesful 00051 * or 0 if it failed. But it might be 0 too wether your result has 0 in length. 00052 */ 00053 unsigned int get(const char *url, char *result = NULL, int rsize = 64); 00054 00055 /** 00056 * @brief A simple get-request just insert the url and a FILE Pointer. 00057 * This get request will save yor result to an file. Very helpful if you demat a big bunch of data. 00058 * 00059 * @param url The requested URL. 00060 * @param result The FILE Pointer in which you want to store the result. 00061 * @result The length of your demanted result or 1 if the request is succssesful 00062 * or 0 if it failed. But it might be 0 too wether your result has 0 in length. 00063 */ 00064 unsigned int get(const char *url, FILE *result); 00065 00066 /** 00067 * @brief A simple post-request just insert the url. 00068 * You can send data if you want but they should be NULL-Terminated. 00069 * If you want you can get the result back as a string. 00070 * Sometimes you want get a large result, more than 64 Bytes 00071 * than define your size. 00072 * 00073 * @param url The requested URL. 00074 * @param data A char array of the data you might want to send. 00075 * @param result The answere to your request, by default you have not to take it. 00076 * But if you want it, it has a default length from 64 Bytes. 00077 * @param rsize The maximum size of your result. By default 64 Bytes. 00078 * @result The length of your demanted result or 1 if the request is succssesful 00079 * or 0 if it failed. But it might be 0 too wether your result has 0 in length. 00080 */ 00081 unsigned int post(const char *url, const char *data = NULL, char *result = NULL, int rsize = 64); 00082 00083 /** 00084 * @brief A simple get-request just insert the url and a FILE Pointer. 00085 * You can send data if you want but they should be NULL-Terminated. 00086 * This get request will save yor result to an file. Very helpful if you demat a big bunch of data. 00087 * 00088 * @param url The requested URL. 00089 * @param data A char array of the data you might want to send. 00090 * @param result The FILE Pointer in which you want to store the result. 00091 * @result The length of your demanted result or 1 if the request is succssesful 00092 * or 0 if it failed. But it might be 0 too wether your result has 0 in length. 00093 */ 00094 unsigned int post(const char *url, const char *data, FILE *result); 00095 00096 /** 00097 * @brief A simple get-request just insert the url and a two FILE Pointers to send the content of the file out and store you results. 00098 * Your data to sent can come from a file. 00099 * This get request will save yor result to an file. Very helpful if you demat a big bunch of data. 00100 * 00101 * @param url The requested URL. 00102 * @param data A FILE Pointer of a file you might want to send. 00103 * @param result The FILE Pointer in which you want to store the result. 00104 * @result The length of your demanted result or 1 if the request is succssesful 00105 * or 0 if it failed. But it might be 0 too wether your result has 0 in length. 00106 */ 00107 unsigned int post(const char *url, FILE *data, FILE *result); 00108 00109 /** 00110 * @brief A simple get-request just insert the url and a two FILE Pointers to send the content of the file out and store you results. 00111 * Your data to sent can come from a file. 00112 * If you want you can get the result back as a string. 00113 * Sometimes you want get a large result, more than 64 Bytes 00114 * than define your size. 00115 * 00116 * @param url The requested URL. 00117 * @param data A FILE Pointer of a file you might want to send. 00118 * @param result The answere to your request, by default you have not to take it. 00119 * But if you want it, it has a default length from 64 Bytes. 00120 * @param rsize The maximum size of your result. By default 64 Bytes. 00121 * @result The length of your demanted result or 1 if the request is succssesful 00122 * or 0 if it failed. But it might be 0 too wether your result has 0 in length. 00123 */ 00124 unsigned int post(const char *url, FILE *data = NULL, char *result = NULL, int length = 64); 00125 00126 private: 00127 virtual void err(err_t err); 00128 virtual err_t poll(); 00129 virtual err_t sent(u16_t len) {return ERR_OK;}; 00130 virtual err_t connected(err_t err); 00131 virtual err_t recv(struct pbuf *q, err_t err); 00132 virtual void dnsreply(const char *hostname, struct ip_addr *ipaddr); 00133 unsigned int make(const char *); 00134 00135 char *_auth; 00136 bool _ready; 00137 char _mode; 00138 char _state; 00139 char _timeout; 00140 const char *_host; 00141 const char *_path; 00142 void *_result; 00143 void *_data; 00144 const char *_request; 00145 const char *_headerfields; 00146 unsigned int _hostlen; 00147 unsigned int _resultoff; 00148 unsigned int _resultleft; 00149 }; 00150 00151 #endif
Generated on Tue Jul 12 2022 16:06:06 by 1.7.2