When Arduino acts as client, is he who sends request and has to manage response from server.
To send requestwith GET method just create a resource string and a possible query (with parameters). If client is a reduced hardware as Arduino, it, usually, sends a request to a CGI server (or PHP,Servelet,JSP...).
So, it substantially sends data within the request in the form of parameters in a query string.
For example : /logdata?A1=220&A2=34&D4=on (query starts with ?)
To help you for query string making, a setParameter function is provided.
To send request with POST method you have to use separate parameters for resource name and data. Data will be added at the end of http packet and you can use any format for data (values sequence, XML, JSON) but null terminated string in any way.
HTTP.sendRequestGET(int socket,char *uriresource)
HTTP.sendRequestGET(int socket,char *headers[],int nh,char *uriresource)
socket : link socket
a char string containing resource+query
headers[]: array of strings
nh: number of headers (array dimension)
none
HTTP.sendRequestPOST(int socket,char *uriresource,char *data)
HTTP.sendRequestPOST(int socket,char *headers[],int nh,char *uriresource,char *data)
socket : link socket
a char string containing resource name
a char string (null terminated string) containing data
headers[]: array of strings
nh: number of headers (array dimension)
none
HTTP.sendRequestPUT(int socket,char *uriresource,char *data)
HTTP.sendRequestPUT(int socket,char *headers[],int nh,char *uriresource,char *data)
socket : link socket
a char string containing resource name
a char string (null terminated string) containing data
headers[]: array of strings
nh: number of headers (array dimension)
none
HTTP.sendRequestDELETE(int socket,char *uriresource)
HTTP.sendRequestDELETE(int socket,char *headers[],int nh,char *uriresource)
socket : link socket
a char string containing resource name
headers[]: array of strings
nh: number of headers (array dimension)
none
To format query string you can use addParameter function
This function adds a coded couple name-value to a buffer urlresource.
(query in a request has some particular char coded : space become + etc.)
addParameter(char *urlresource,int dimres, char *parname,char *parvalue)
pointer to a char buffer long enough to contain resource+query
length of this buffer
name of parameter
value of parameter ; if NULL the function uses parname as resource name (i.e initialize urlresurce)
none directly (void) but urlresource buffer filled
if buffer too short query is truncated
#include <HTTPlib.h> //library include
HTTP WIFI; //instance of HTTP (inherits any stuff of MWiFi)
:
:
char url[64];
setParameter(url,64,"/logdata".NULL);
setParameter(url,64,"A1","220");
setParameter(url,64,"A2","34");
setParameter(url,64,"D4","on");
sendRequest(csocket,url);