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