-19-
v7.0
Software
3.10.2. HTTP request methods
The
http()
function configures HTTP parameters, performs the request selected by the user and handles the data
returned from the server.
This function needs several parameters to work properly depending on the method used. The 1st parameter
required by the function is the request method. User can choose among 5 methods: GET, HEAD, DELETE, POST
and PUT:
WaspBG96::HTTP_GET
WaspBG96::HTTP_HEAD
WaspBG96::HTTP_DELETE
WaspBG96::HTTP_POST
WaspBG96::HTTP_PUT
After choosing the method, the function needs the host URL, port and resource of the HTTP server requested. The
data field is only necessary when POST or PUT methods are performed.
Example of use (GET, HEAD and DELETE methods):
{
char host[] = “test.libelium.com”;
uint16_t port = 80;
char resource[] = “/test-get-post.php?varA=1&varB=2&varC=3&varD=4”;
BG96.http(WaspBG96::HTTP_GET, host, port, resource);
}
Example of use (POST and PUT methods):
{
char host[] = “test.libelium.com”;
uint16_t port = 80;
char resource[] = “/test-get-post.php”;
char data[] = “varA=1&varB=2&varC=3&varD=4&varE=5”;
BG96.http(WaspBG96::HTTP_POST, host, port, resource, data);
}
Once the request has been sent, the function waits for data from the server and stores it in
_buffer
. It also stores
the HTTP status code from the server in
_httpCode
.
Related variables:
BG96._httpCode
→
Stores the HTTP code from the server
BG96._buffer
→
Stores data received from server
BG96._length
→
Stores data length
Example of HTTP GET:
www.libelium.com/development/waspmote/examples/nb-iot-06-http-get
Example of HTTP POST:
www.libelium.com/development/waspmote/examples/nb-iot-07-http-post