Page 1 of 1

Example of HTTP Post request for sending json data

Posted: Thu Jun 16, 2016 8:18 am
by seeker
Hi,

Can you please post an example program for sending JSON data through HTTP Post request, using GRPS ?

Re: Example of HTTP Post request for sending json data

Posted: Thu Jun 16, 2016 12:55 pm
by libelium-dev
Hi,

Here is the example to make a HTTP POST request, we don't use the JSON format to send data so we dont know if it will work.
http://www.libelium.com/development/was ... with-post/

Also you can try opening a TCP connection.
http://www.libelium.com/development/was ... onnection/

Regards

Re: Example of HTTP Post request for sending json data

Posted: Fri Jun 17, 2016 12:39 pm
by seeker
Nevermind, I programmed the server to work with www-formurlencoded data. Thanks anyways! :)

Re: Example of HTTP Post request for sending json data

Posted: Fri Jun 17, 2016 1:17 pm
by libelium-dev
You're welcome!

Re: Example of HTTP Post request for sending json data

Posted: Mon Aug 26, 2019 6:14 pm
by Carlosrod298
I made this code for sending in json format

void SendHttpData(){
//////////////////////////////////////////////////
// 1. Switch ON
//////////////////////////////////////////////////
error = WIFI_PRO.ON(socket);
if (error != 0)
{
USB.println(F("1. WiFi did not initialize correctly"));
ErrCount++;
}
else
{
// 2. Set url
error = WIFI_PRO.setURL( type, host, port, url );
if (error == 0)
{ USB.println(F("2. setURL OK"));
}
else
{
USB.println(F("2. Error calling 'setURL' function"));
WIFI_PRO.printErrorCode();
}
//Set content Type
error = WIFI_PRO.setContentType(ContentType);
// check response
if (error == 0)
{
USB.println(F("2. setContentType OK"));
}
else
{
USB.println(F("2. Error calling 'setContentType' function"));
WIFI_PRO.printErrorCode();
}


//////////////////////////////////////////////////
// 3. Join AP
//////////////////////////////////////////////////
// check connectivity
status = WIFI_PRO.isConnected();
// Check if module is connected
if (status == true)
{
USB.println(F("3. WiFi is connected OK"));

USB.println(body);

////////////////////////////////////////////////
// 3.1. http request
////////////////////////////////////////////////
error = WIFI_PRO.post(body);
// check response
if (error == 0)
{
USB.print(F("3.1. HTTP POST OK. "));
USB.print(F("HTTP Time from OFF state (ms):"));

USB.print(F("\nServer answer:"));
USB.print(F(WIFI_PRO._buffer,WIFI_PRO.length)
}
}

Re: Example of HTTP Post request for sending json data

Posted: Tue Aug 27, 2019 8:33 am
by libelium-dev
Thanks for your contribution to the forum.