Example of HTTPServer with additional features: * SNTPClient, DST rules * Link status indication * Local or SDCard-based WebServer * RPC-able class * Static and Dynamic HTML page
lwip/HTTPClient/HTTPClient.cpp@0:886e4b3119ad, 2010-01-03 (annotated)
- Committer:
- iva2k
- Date:
- Sun Jan 03 07:00:43 2010 +0000
- Revision:
- 0:886e4b3119ad
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iva2k | 0:886e4b3119ad | 1 | #include "HTTPClient.h" |
iva2k | 0:886e4b3119ad | 2 | #include "NetServer.h" |
iva2k | 0:886e4b3119ad | 3 | #include "iputil.h" |
iva2k | 0:886e4b3119ad | 4 | |
iva2k | 0:886e4b3119ad | 5 | using namespace mbed; |
iva2k | 0:886e4b3119ad | 6 | using namespace std; |
iva2k | 0:886e4b3119ad | 7 | |
iva2k | 0:886e4b3119ad | 8 | #define POST 0x1 |
iva2k | 0:886e4b3119ad | 9 | #define FDATA 0x2 |
iva2k | 0:886e4b3119ad | 10 | #define FRES 0x4 |
iva2k | 0:886e4b3119ad | 11 | #define GET 0x0 |
iva2k | 0:886e4b3119ad | 12 | #define CDATA 0x0 |
iva2k | 0:886e4b3119ad | 13 | #define CRES 0x0 |
iva2k | 0:886e4b3119ad | 14 | |
iva2k | 0:886e4b3119ad | 15 | long fleft(FILE *fd) { |
iva2k | 0:886e4b3119ad | 16 | long len, cur; |
iva2k | 0:886e4b3119ad | 17 | cur = ftell(fd); |
iva2k | 0:886e4b3119ad | 18 | fseek(fd, 0, SEEK_END); |
iva2k | 0:886e4b3119ad | 19 | len = ftell(fd); |
iva2k | 0:886e4b3119ad | 20 | fseek(fd, cur, SEEK_SET); |
iva2k | 0:886e4b3119ad | 21 | return len; |
iva2k | 0:886e4b3119ad | 22 | } |
iva2k | 0:886e4b3119ad | 23 | |
iva2k | 0:886e4b3119ad | 24 | |
iva2k | 0:886e4b3119ad | 25 | HTTPClient::HTTPClient(const char *hostname, struct ip_addr ip, struct ip_addr nm, struct ip_addr gw, struct ip_addr dns) |
iva2k | 0:886e4b3119ad | 26 | : TCPConnection(), _auth(NULL), _timeout(0), _data(NULL), _headerfields(NULL), _timeout_max(60000) { |
iva2k | 0:886e4b3119ad | 27 | NetServer *net = NULL; |
iva2k | 0:886e4b3119ad | 28 | if(ip.addr != ip_addr_any.addr && nm.addr != ip_addr_any.addr && gw.addr != ip_addr_any.addr) { |
iva2k | 0:886e4b3119ad | 29 | net = NetServer::create(ip, nm, gw); |
iva2k | 0:886e4b3119ad | 30 | if(dns.addr != ip_addr_any.addr) { |
iva2k | 0:886e4b3119ad | 31 | net->setDNS1(dns); |
iva2k | 0:886e4b3119ad | 32 | } |
iva2k | 0:886e4b3119ad | 33 | } else if(hostname) { |
iva2k | 0:886e4b3119ad | 34 | net = NetServer::create(); |
iva2k | 0:886e4b3119ad | 35 | } |
iva2k | 0:886e4b3119ad | 36 | if(hostname) { |
iva2k | 0:886e4b3119ad | 37 | net->setHostname(hostname); |
iva2k | 0:886e4b3119ad | 38 | } |
iva2k | 0:886e4b3119ad | 39 | } |
iva2k | 0:886e4b3119ad | 40 | |
iva2k | 0:886e4b3119ad | 41 | void HTTPClient::timeout(int value) { |
iva2k | 0:886e4b3119ad | 42 | _timeout_max = value; |
iva2k | 0:886e4b3119ad | 43 | } |
iva2k | 0:886e4b3119ad | 44 | |
iva2k | 0:886e4b3119ad | 45 | void HTTPClient::err(err_t err) { |
iva2k | 0:886e4b3119ad | 46 | release_callbacks(); |
iva2k | 0:886e4b3119ad | 47 | } |
iva2k | 0:886e4b3119ad | 48 | |
iva2k | 0:886e4b3119ad | 49 | err_t HTTPClient::poll() { |
iva2k | 0:886e4b3119ad | 50 | if(NetServer::time() - _timeout > _timeout_max) { |
iva2k | 0:886e4b3119ad | 51 | release_callbacks(); |
iva2k | 0:886e4b3119ad | 52 | close(); |
iva2k | 0:886e4b3119ad | 53 | printf("TIMEOUT\n"); |
iva2k | 0:886e4b3119ad | 54 | _ready = true; |
iva2k | 0:886e4b3119ad | 55 | _state = 99; |
iva2k | 0:886e4b3119ad | 56 | } |
iva2k | 0:886e4b3119ad | 57 | return ERR_OK; |
iva2k | 0:886e4b3119ad | 58 | } |
iva2k | 0:886e4b3119ad | 59 | |
iva2k | 0:886e4b3119ad | 60 | void HTTPClient::dnsreply(const char *hostname, struct ip_addr *ipaddr) { |
iva2k | 0:886e4b3119ad | 61 | _ready = true; |
iva2k | 0:886e4b3119ad | 62 | _ipaddr = *ipaddr; |
iva2k | 0:886e4b3119ad | 63 | _state = (ipaddr==NULL)? 99 : 0; |
iva2k | 0:886e4b3119ad | 64 | _timeout = NetServer::time(); |
iva2k | 0:886e4b3119ad | 65 | } |
iva2k | 0:886e4b3119ad | 66 | |
iva2k | 0:886e4b3119ad | 67 | err_t HTTPClient::connected(err_t err) { |
iva2k | 0:886e4b3119ad | 68 | TCPConnection::connected(err); |
iva2k | 0:886e4b3119ad | 69 | _ready = false; |
iva2k | 0:886e4b3119ad | 70 | _state = 0; |
iva2k | 0:886e4b3119ad | 71 | _resultoff = 0; |
iva2k | 0:886e4b3119ad | 72 | if(_mode&POST) { |
iva2k | 0:886e4b3119ad | 73 | write((void *)"POST ", 5, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 74 | } else { |
iva2k | 0:886e4b3119ad | 75 | write((void *)"GET ", 4, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 76 | } |
iva2k | 0:886e4b3119ad | 77 | if(strlen(_path) == 0) { |
iva2k | 0:886e4b3119ad | 78 | write((void *)"/", 1, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 79 | } else { |
iva2k | 0:886e4b3119ad | 80 | write((void *)_path, strlen(_path), TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 81 | } |
iva2k | 0:886e4b3119ad | 82 | write((void *)" HTTP/1.1\r\nHost: ", 17, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 83 | write((void *)_host, _hostlen, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 84 | if(_auth&&(*_auth!='\0')) { |
iva2k | 0:886e4b3119ad | 85 | write((void *)"\r\nAuthorization: Basic ", 23, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 86 | write((void *)_auth, strlen(_auth), TCP_WRITE_FLAG_COPY |TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 87 | } |
iva2k | 0:886e4b3119ad | 88 | if(_headerfields&&(*_headerfields!='\0')) { |
iva2k | 0:886e4b3119ad | 89 | write((void *)"\r\n", 2, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 90 | write((void *)_headerfields, strlen(_headerfields), TCP_WRITE_FLAG_COPY |TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 91 | } |
iva2k | 0:886e4b3119ad | 92 | write((void *)"\r\nConnection: Close\r\n", 21, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_COPY); |
iva2k | 0:886e4b3119ad | 93 | if(_data) { |
iva2k | 0:886e4b3119ad | 94 | char clen[256]; |
iva2k | 0:886e4b3119ad | 95 | int len, blen; |
iva2k | 0:886e4b3119ad | 96 | if(_mode&FDATA) { |
iva2k | 0:886e4b3119ad | 97 | //printf("Send file\n"); |
iva2k | 0:886e4b3119ad | 98 | len = fleft((FILE *)_data); |
iva2k | 0:886e4b3119ad | 99 | sprintf(clen, "Content-Length: %d\r\n\r\n\0", len); |
iva2k | 0:886e4b3119ad | 100 | write((void *)clen, strlen(clen), TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_COPY); |
iva2k | 0:886e4b3119ad | 101 | if(len) { |
iva2k | 0:886e4b3119ad | 102 | do { |
iva2k | 0:886e4b3119ad | 103 | int sb = sndbuf(); |
iva2k | 0:886e4b3119ad | 104 | blen = fread(clen, sizeof(char), (int)min(sb, 100), (FILE *)_data); |
iva2k | 0:886e4b3119ad | 105 | write(clen, blen, (TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE)); |
iva2k | 0:886e4b3119ad | 106 | len -= blen; |
iva2k | 0:886e4b3119ad | 107 | } while(len > 1 && blen); |
iva2k | 0:886e4b3119ad | 108 | } |
iva2k | 0:886e4b3119ad | 109 | } else { |
iva2k | 0:886e4b3119ad | 110 | len = strlen((const char *)_data); |
iva2k | 0:886e4b3119ad | 111 | sprintf(clen, "Content-Length: %d\r\n\r\n\0", len); |
iva2k | 0:886e4b3119ad | 112 | write((void *)clen, strlen(clen), TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_COPY); |
iva2k | 0:886e4b3119ad | 113 | write((void *)_data, len, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); |
iva2k | 0:886e4b3119ad | 114 | } |
iva2k | 0:886e4b3119ad | 115 | } |
iva2k | 0:886e4b3119ad | 116 | write((void *)"\r\n", 2, TCP_WRITE_FLAG_COPY); |
iva2k | 0:886e4b3119ad | 117 | _timeout = NetServer::time(); |
iva2k | 0:886e4b3119ad | 118 | return ERR_OK; |
iva2k | 0:886e4b3119ad | 119 | } |
iva2k | 0:886e4b3119ad | 120 | |
iva2k | 0:886e4b3119ad | 121 | #define _min(x, y) (((x)<(y))?(x):(y)) |
iva2k | 0:886e4b3119ad | 122 | err_t HTTPClient::recv(struct pbuf *p, err_t err) { |
iva2k | 0:886e4b3119ad | 123 | if(err == ERR_OK && p != NULL&&_state<10) { |
iva2k | 0:886e4b3119ad | 124 | _timeout = NetServer::time(); |
iva2k | 0:886e4b3119ad | 125 | struct pbuf *q = p; |
iva2k | 0:886e4b3119ad | 126 | char *d = (char *)q->payload; |
iva2k | 0:886e4b3119ad | 127 | recved(p->tot_len); |
iva2k | 0:886e4b3119ad | 128 | |
iva2k | 0:886e4b3119ad | 129 | while(q&&_state<10) { |
iva2k | 0:886e4b3119ad | 130 | unsigned int end = ((unsigned int)(q->payload)+(unsigned int)(q->len)); |
iva2k | 0:886e4b3119ad | 131 | switch(_state) { |
iva2k | 0:886e4b3119ad | 132 | case 0: { |
iva2k | 0:886e4b3119ad | 133 | for(; _state==0 && ((unsigned int)d < end); d++) { |
iva2k | 0:886e4b3119ad | 134 | if((*((char *)(d-0))=='\n')&&(*((char *)(d-1))=='\r')&& |
iva2k | 0:886e4b3119ad | 135 | (*((char *)(d-2))=='\n')&&(*((char *)(d-3))=='\r')) { |
iva2k | 0:886e4b3119ad | 136 | _state = 1; |
iva2k | 0:886e4b3119ad | 137 | d += 1; |
iva2k | 0:886e4b3119ad | 138 | break; |
iva2k | 0:886e4b3119ad | 139 | } |
iva2k | 0:886e4b3119ad | 140 | } |
iva2k | 0:886e4b3119ad | 141 | } break; |
iva2k | 0:886e4b3119ad | 142 | case 1: { |
iva2k | 0:886e4b3119ad | 143 | if(_result) { |
iva2k | 0:886e4b3119ad | 144 | if(_mode&FRES) { |
iva2k | 0:886e4b3119ad | 145 | fwrite(d, sizeof(char), end - (unsigned int)d, (FILE *)_result); |
iva2k | 0:886e4b3119ad | 146 | _resultoff += (end - (unsigned int)d); |
iva2k | 0:886e4b3119ad | 147 | d = (char *)end; |
iva2k | 0:886e4b3119ad | 148 | } else { |
iva2k | 0:886e4b3119ad | 149 | unsigned int len = _min(_resultleft, (end-(unsigned int)d)); |
iva2k | 0:886e4b3119ad | 150 | memcpy((char *)_result + _resultoff, d, len); |
iva2k | 0:886e4b3119ad | 151 | _resultleft -= len; |
iva2k | 0:886e4b3119ad | 152 | _resultoff += len; |
iva2k | 0:886e4b3119ad | 153 | d += len; |
iva2k | 0:886e4b3119ad | 154 | |
iva2k | 0:886e4b3119ad | 155 | if(!_resultleft) { |
iva2k | 0:886e4b3119ad | 156 | _state = 10; |
iva2k | 0:886e4b3119ad | 157 | } |
iva2k | 0:886e4b3119ad | 158 | } |
iva2k | 0:886e4b3119ad | 159 | } else { |
iva2k | 0:886e4b3119ad | 160 | _state = 10; |
iva2k | 0:886e4b3119ad | 161 | } |
iva2k | 0:886e4b3119ad | 162 | } break; |
iva2k | 0:886e4b3119ad | 163 | default: { |
iva2k | 0:886e4b3119ad | 164 | break; |
iva2k | 0:886e4b3119ad | 165 | } |
iva2k | 0:886e4b3119ad | 166 | } |
iva2k | 0:886e4b3119ad | 167 | if(_state<10&&(unsigned int)d==end) { |
iva2k | 0:886e4b3119ad | 168 | q = q->next; |
iva2k | 0:886e4b3119ad | 169 | if(q) { |
iva2k | 0:886e4b3119ad | 170 | d = static_cast<char *>(q->payload); |
iva2k | 0:886e4b3119ad | 171 | } |
iva2k | 0:886e4b3119ad | 172 | } |
iva2k | 0:886e4b3119ad | 173 | } |
iva2k | 0:886e4b3119ad | 174 | } |
iva2k | 0:886e4b3119ad | 175 | |
iva2k | 0:886e4b3119ad | 176 | if(p!=NULL) { |
iva2k | 0:886e4b3119ad | 177 | pbuf_free(p); |
iva2k | 0:886e4b3119ad | 178 | } |
iva2k | 0:886e4b3119ad | 179 | |
iva2k | 0:886e4b3119ad | 180 | if(_state>10||p==NULL||err!=ERR_OK) { |
iva2k | 0:886e4b3119ad | 181 | release_callbacks(); |
iva2k | 0:886e4b3119ad | 182 | close(); |
iva2k | 0:886e4b3119ad | 183 | _ready = true; |
iva2k | 0:886e4b3119ad | 184 | } |
iva2k | 0:886e4b3119ad | 185 | return ERR_OK; |
iva2k | 0:886e4b3119ad | 186 | } |
iva2k | 0:886e4b3119ad | 187 | |
iva2k | 0:886e4b3119ad | 188 | unsigned int HTTPClient::make(const char *request) { |
iva2k | 0:886e4b3119ad | 189 | _request = request; |
iva2k | 0:886e4b3119ad | 190 | _resultoff = 0; |
iva2k | 0:886e4b3119ad | 191 | _ready = false; |
iva2k | 0:886e4b3119ad | 192 | _state = 0; |
iva2k | 0:886e4b3119ad | 193 | _hostlen = 0; |
iva2k | 0:886e4b3119ad | 194 | _port = 0; |
iva2k | 0:886e4b3119ad | 195 | _timeout = NetServer::time(); |
iva2k | 0:886e4b3119ad | 196 | NetServer::ready(); |
iva2k | 0:886e4b3119ad | 197 | |
iva2k | 0:886e4b3119ad | 198 | int hostlen = 0; |
iva2k | 0:886e4b3119ad | 199 | if(strlen(_request)<10||strncmp("http://", _request, 7)!=0) { |
iva2k | 0:886e4b3119ad | 200 | printf("Only http requests are allowed\n"); |
iva2k | 0:886e4b3119ad | 201 | return 0; |
iva2k | 0:886e4b3119ad | 202 | } |
iva2k | 0:886e4b3119ad | 203 | _path = _host = _request + 6; |
iva2k | 0:886e4b3119ad | 204 | _host++; |
iva2k | 0:886e4b3119ad | 205 | while(!_state == 1) { |
iva2k | 0:886e4b3119ad | 206 | switch(*(++_path)) { |
iva2k | 0:886e4b3119ad | 207 | case ':': |
iva2k | 0:886e4b3119ad | 208 | _port = atoi(_path+1); |
iva2k | 0:886e4b3119ad | 209 | break; |
iva2k | 0:886e4b3119ad | 210 | case '/': |
iva2k | 0:886e4b3119ad | 211 | case '\0': |
iva2k | 0:886e4b3119ad | 212 | _port = (_port)?_port:80; |
iva2k | 0:886e4b3119ad | 213 | _state = 1; |
iva2k | 0:886e4b3119ad | 214 | break; |
iva2k | 0:886e4b3119ad | 215 | default: |
iva2k | 0:886e4b3119ad | 216 | break; |
iva2k | 0:886e4b3119ad | 217 | } |
iva2k | 0:886e4b3119ad | 218 | if(!_port) { |
iva2k | 0:886e4b3119ad | 219 | hostlen++; |
iva2k | 0:886e4b3119ad | 220 | } |
iva2k | 0:886e4b3119ad | 221 | if(!_state == 1) { |
iva2k | 0:886e4b3119ad | 222 | _hostlen++; |
iva2k | 0:886e4b3119ad | 223 | } |
iva2k | 0:886e4b3119ad | 224 | } |
iva2k | 0:886e4b3119ad | 225 | _state = 0; |
iva2k | 0:886e4b3119ad | 226 | |
iva2k | 0:886e4b3119ad | 227 | if(hostlen>256) { |
iva2k | 0:886e4b3119ad | 228 | printf("Hostname longer than allowed\n"); |
iva2k | 0:886e4b3119ad | 229 | return 0; |
iva2k | 0:886e4b3119ad | 230 | } |
iva2k | 0:886e4b3119ad | 231 | |
iva2k | 0:886e4b3119ad | 232 | char host[257]; |
iva2k | 0:886e4b3119ad | 233 | memcpy(host, _host, hostlen); |
iva2k | 0:886e4b3119ad | 234 | host[hostlen] = 0; |
iva2k | 0:886e4b3119ad | 235 | _timeout = NetServer::time(); |
iva2k | 0:886e4b3119ad | 236 | struct in_addr in; |
iva2k | 0:886e4b3119ad | 237 | if(!inet_aton(host, &in)) { |
iva2k | 0:886e4b3119ad | 238 | _ready = false; |
iva2k | 0:886e4b3119ad | 239 | if(dnsrequest(host, &_ipaddr)==ERR_INPROGRESS) { |
iva2k | 0:886e4b3119ad | 240 | while(!_ready) { |
iva2k | 0:886e4b3119ad | 241 | NetServer::poll(); |
iva2k | 0:886e4b3119ad | 242 | wait_ms(10); |
iva2k | 0:886e4b3119ad | 243 | } |
iva2k | 0:886e4b3119ad | 244 | if(_state==99) { |
iva2k | 0:886e4b3119ad | 245 | printf("Server not found\n"); |
iva2k | 0:886e4b3119ad | 246 | return 0; |
iva2k | 0:886e4b3119ad | 247 | } |
iva2k | 0:886e4b3119ad | 248 | } |
iva2k | 0:886e4b3119ad | 249 | } else { |
iva2k | 0:886e4b3119ad | 250 | _ipaddr.addr = in.s_addr; |
iva2k | 0:886e4b3119ad | 251 | } |
iva2k | 0:886e4b3119ad | 252 | |
iva2k | 0:886e4b3119ad | 253 | _ready = false; |
iva2k | 0:886e4b3119ad | 254 | _timeout = NetServer::time(); |
iva2k | 0:886e4b3119ad | 255 | connect(); |
iva2k | 0:886e4b3119ad | 256 | set_poll_interval(10); |
iva2k | 0:886e4b3119ad | 257 | tcp_setprio(_pcb, TCP_PRIO_MIN); |
iva2k | 0:886e4b3119ad | 258 | while(!_ready) { |
iva2k | 0:886e4b3119ad | 259 | NetServer::poll(); |
iva2k | 0:886e4b3119ad | 260 | wait_ms(10); |
iva2k | 0:886e4b3119ad | 261 | } |
iva2k | 0:886e4b3119ad | 262 | //release_callbacks(); |
iva2k | 0:886e4b3119ad | 263 | close(); |
iva2k | 0:886e4b3119ad | 264 | if(_state==99) { |
iva2k | 0:886e4b3119ad | 265 | printf("Connection error\n"); |
iva2k | 0:886e4b3119ad | 266 | return 0; |
iva2k | 0:886e4b3119ad | 267 | } |
iva2k | 0:886e4b3119ad | 268 | |
iva2k | 0:886e4b3119ad | 269 | if(!_mode&FRES&&_result) { |
iva2k | 0:886e4b3119ad | 270 | ((char *)_result)[_resultoff+1] = '\0'; |
iva2k | 0:886e4b3119ad | 271 | } |
iva2k | 0:886e4b3119ad | 272 | return ((!_mode&FRES)&&!_result)?1:_resultoff; |
iva2k | 0:886e4b3119ad | 273 | |
iva2k | 0:886e4b3119ad | 274 | } |
iva2k | 0:886e4b3119ad | 275 | |
iva2k | 0:886e4b3119ad | 276 | void HTTPClient::auth(const char *user, const char *password) { |
iva2k | 0:886e4b3119ad | 277 | if(user) { |
iva2k | 0:886e4b3119ad | 278 | char up[256]; |
iva2k | 0:886e4b3119ad | 279 | sprintf(up, "%s:%s", user, password); |
iva2k | 0:886e4b3119ad | 280 | _auth = new char[base64enc_len(up)+1]; |
iva2k | 0:886e4b3119ad | 281 | base64enc(up, strlen(up), _auth); |
iva2k | 0:886e4b3119ad | 282 | } else if(_auth) { |
iva2k | 0:886e4b3119ad | 283 | delete _auth; |
iva2k | 0:886e4b3119ad | 284 | _auth = NULL; |
iva2k | 0:886e4b3119ad | 285 | } |
iva2k | 0:886e4b3119ad | 286 | } |
iva2k | 0:886e4b3119ad | 287 | |
iva2k | 0:886e4b3119ad | 288 | void HTTPClient::headers(const char *fields) { |
iva2k | 0:886e4b3119ad | 289 | _headerfields = fields; |
iva2k | 0:886e4b3119ad | 290 | } |
iva2k | 0:886e4b3119ad | 291 | |
iva2k | 0:886e4b3119ad | 292 | unsigned int HTTPClient::get(const char *url, char *result, int rsize) { |
iva2k | 0:886e4b3119ad | 293 | _mode = GET | CDATA | CRES; |
iva2k | 0:886e4b3119ad | 294 | _data = (void *)NULL; |
iva2k | 0:886e4b3119ad | 295 | _result = (void *)result; |
iva2k | 0:886e4b3119ad | 296 | _resultleft = rsize -1; |
iva2k | 0:886e4b3119ad | 297 | |
iva2k | 0:886e4b3119ad | 298 | return make(url); |
iva2k | 0:886e4b3119ad | 299 | } |
iva2k | 0:886e4b3119ad | 300 | |
iva2k | 0:886e4b3119ad | 301 | unsigned int HTTPClient::get(const char *url, FILE *result) { |
iva2k | 0:886e4b3119ad | 302 | _mode = GET | CDATA | FRES; |
iva2k | 0:886e4b3119ad | 303 | _data = (void *)NULL; |
iva2k | 0:886e4b3119ad | 304 | _result = (void *)result; |
iva2k | 0:886e4b3119ad | 305 | _resultleft = 0; |
iva2k | 0:886e4b3119ad | 306 | |
iva2k | 0:886e4b3119ad | 307 | return make(url); |
iva2k | 0:886e4b3119ad | 308 | } |
iva2k | 0:886e4b3119ad | 309 | |
iva2k | 0:886e4b3119ad | 310 | unsigned int HTTPClient::post(const char *url, const char *data, char *result, int rsize) { |
iva2k | 0:886e4b3119ad | 311 | _mode = POST | CDATA | CRES; |
iva2k | 0:886e4b3119ad | 312 | _data = (void *)data; |
iva2k | 0:886e4b3119ad | 313 | _result = (void *)result; |
iva2k | 0:886e4b3119ad | 314 | _resultleft = rsize -1; |
iva2k | 0:886e4b3119ad | 315 | |
iva2k | 0:886e4b3119ad | 316 | return make(url); |
iva2k | 0:886e4b3119ad | 317 | } |
iva2k | 0:886e4b3119ad | 318 | |
iva2k | 0:886e4b3119ad | 319 | unsigned int HTTPClient::post(const char *url, const char *data, FILE *result) { |
iva2k | 0:886e4b3119ad | 320 | _mode = POST | CDATA | FRES; |
iva2k | 0:886e4b3119ad | 321 | _data = (void *)data; |
iva2k | 0:886e4b3119ad | 322 | _result = (void *)result; |
iva2k | 0:886e4b3119ad | 323 | _resultleft = 0; |
iva2k | 0:886e4b3119ad | 324 | |
iva2k | 0:886e4b3119ad | 325 | return make(url); |
iva2k | 0:886e4b3119ad | 326 | } |
iva2k | 0:886e4b3119ad | 327 | |
iva2k | 0:886e4b3119ad | 328 | unsigned int HTTPClient::post(const char *url, FILE *data, FILE *result) { |
iva2k | 0:886e4b3119ad | 329 | _mode = POST | FDATA | FRES; |
iva2k | 0:886e4b3119ad | 330 | _data = (void *)data; |
iva2k | 0:886e4b3119ad | 331 | _result = (void *)result; |
iva2k | 0:886e4b3119ad | 332 | _resultleft = 0; |
iva2k | 0:886e4b3119ad | 333 | |
iva2k | 0:886e4b3119ad | 334 | return make(url); |
iva2k | 0:886e4b3119ad | 335 | } |
iva2k | 0:886e4b3119ad | 336 | |
iva2k | 0:886e4b3119ad | 337 | unsigned int HTTPClient::post(const char *url, FILE *data, char *result, int rsize) { |
iva2k | 0:886e4b3119ad | 338 | _mode = POST | FDATA | CRES; |
iva2k | 0:886e4b3119ad | 339 | _data = (void *)data; |
iva2k | 0:886e4b3119ad | 340 | _result = (void *)result; |
iva2k | 0:886e4b3119ad | 341 | _resultleft = rsize -1; |
iva2k | 0:886e4b3119ad | 342 | |
iva2k | 0:886e4b3119ad | 343 | return make(url); |
iva2k | 0:886e4b3119ad | 344 | } |
iva2k | 0:886e4b3119ad | 345 |