api / EMAC / lwip / trunk / HTTPClient / HTTPClient
HTTPClient
class HTTPClient : public TCPConnection
A simple Class to fetch HTTP Pages.
| HTTPClient | A simple Class to fetch HTTP Pages. |
| Functions | |
| HTTPClient | Creates an HTTPClient object. |
| ~HTTPClient | Destroys the HTTPClient class. |
| headers | Add header additional Information to the next post or get requests. |
| auth | Enables basic authentication. |
| get | A simple get-request just insert the url. |
| get | A simple get-request just insert the url and a FILE Pointer. |
| post | A simple post-request just insert the url. |
| post | A simple get-request just insert the url and a FILE Pointer. |
| post | 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. |
| post | 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. |
| timeout | Sets the timout for a HTTP request. |
HTTPClient
HTTPClient( const char * hostname = NULL, struct ip_addr ip = ip_addr_any, struct ip_addr nm = ip_addr_any, struct ip_addr gw = ip_addr_any, struct ip_addr dns = ip_addr_any )
Creates an HTTPClient object. You might want to initialise the network server befor. If you dont do it it will be happen by the first post or get request you make.
To initialize the network server on creation of the HTTPClient object it’s possible to parse some arguments.
Variables
| hostname | A host name for the device. Might take a while to appear in the network, depends on the network infrastructure. Furthermore in most cases you have to add your domainname after the host name to address the device. Default is NULL. |
| ip | The device ipaddress or ip_addr_any for dhcp. Default is ip_addr_any |
| nm | The device netmask or ip_addr_any for dhcp. Default is ip_addr_any. |
| gw | The device gateway or ip_addr_any for dhcp. Default is ip_addr_any. |
| dns | The device first dns server ip or ip_addr_any for dhcp. Default is ip_addr_any. |
Example
HTTPClient http; // Simple DHCP, brings up the TCP/IP stack on first get/post reguest.
HTTPClient http("worf"); // Brings up the device with DHCP and sets the host name "worf"
// The device will be available under worf.<your local domain>
// for example worf.1-2-3-4.dynamic.sky.comHTTPClient http("wolf", // Brings up the device with static IP address and domain name.
IPv4(192,168,0,44), // IPv4 is a helper function which allows to rtype ipaddresses direct
IPv4(255,255,255,0), // as numbers in C++.
IPv4(192,168,0,1), // the device address is set to 192.168.0.44, netmask 255.255.255.0
IPv4(192,168,0,1)); // default gateway is 192.168.0.1 and dns to 192.168.0.1 as well.headers
void headers( const char * fields )
Add header additional Information to the next post or get requests. Somtimes it is useful to add further header information. For example an auth field. Each time you call this function it will be replace the header fields given by an prior call.
It will not free your data. Variables: fields - A string containing all fields you want to add. Seperated by “\\r\\n”.
auth
void auth( const char * user, const char * password )
Enables basic authentication. Just enter username and password and they will be used for all requests. If you want to lean your username and passwort just insert NULL, NULL.
Variables
| user | Username for ure auth or NULL. |
| password | Password for auth or NULL. |
get
unsigned int get( const char * url, char * result = NULL, int rsize = 64 )
A simple get-request just insert the url. But if you want you can get the result back as a string. Sometimes you want get a large result, more than 64 Bytes than define your size.
Variables
| url | The requested URL. |
| 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. |
| rsize | The maximum size of your result. By default 64 Bytes. |
| 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. |
get
unsigned int get( const char * url, FILE * result )
A simple get-request just insert the url and a FILE Pointer. This get request will save yor result to an file. Very helpful if you demat a big bunch of data.
Variables
| url | The requested URL. |
| result | The FILE Pointer in which you want to store the result. |
| 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. |
post
unsigned int post( const char * url, const char * data = NULL, char * result = NULL, int rsize = 64 )
A simple post-request just insert the url. You can send data if you want but they should be NULL-Terminated. If you want you can get the result back as a string. Sometimes you want get a large result, more than 64 Bytes than define your size.
Variables
| url | The requested URL. |
| data | A char array of the data you might want to send. |
| 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. |
| rsize | The maximum size of your result. By default 64 Bytes. |
| 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. |
post
unsigned int post( const char * url, const char * data, FILE * result )
A simple get-request just insert the url and a FILE Pointer. You can send data if you want but they should be NULL-Terminated. This get request will save yor result to an file. Very helpful if you demat a big bunch of data.
Variables
| url | The requested URL. |
| data | A char array of the data you might want to send. |
| result | The FILE Pointer in which you want to store the result. |
| 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. |
post
unsigned int post( const char * url, FILE * data, FILE * result )
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. Your data to sent can come from a file. This get request will save yor result to an file. Very helpful if you demat a big bunch of data.
Variables
| url | The requested URL. |
| data | A FILE Pointer of a file you might want to send. |
| result | The FILE Pointer in which you want to store the result. |
| 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. |
post
unsigned int post( const char * url, FILE * data = NULL, char * result = NULL, int length = 64 )
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. Your data to sent can come from a file. If you want you can get the result back as a string. Sometimes you want get a large result, more than 64 Bytes than define your size.
| url | The requested URL. |
| data | A FILE Pointer of a file you might want to send. |
| 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. |
| length | The maximum size of your result. By default 64 Bytes. |
| 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. |
A simple Class to fetch HTTP Pages.
class HTTPClient : public TCPConnection
Creates an HTTPClient object.
HTTPClient( const char * hostname = NULL, struct ip_addr ip = ip_addr_any, struct ip_addr nm = ip_addr_any, struct ip_addr gw = ip_addr_any, struct ip_addr dns = ip_addr_any )
Destroys the HTTPClient class.
virtual ~HTTPClient()
Add header additional Information to the next post or get requests.
void headers( const char * fields )
Enables basic authentication.
void auth( const char * user, const char * password )
A simple get-request just insert the url.
unsigned int get( const char * url, char * result = NULL, int rsize = 64 )
A simple post-request just insert the url.
unsigned int post( const char * url, const char * data = NULL, char * result = NULL, int rsize = 64 )
Sets the timout for a HTTP request.
void timeout( int value )
