2018-05-17 01:27 AM
Hi,
I'm using a SPWF04Sx WIFI module.
In AT.HTTPOST command there isn't a field for a JSON payload, but I really need it.
There is something that allow me to send a JSON payload ?
There isn't also a field for the call's header that i've to fill with a token. There is someone that can solve my problems?
Thanks in advance!
#json #spwf04sx #http-post2018-05-17 02:27 AM
Hi,
you have to save the JSON payload in a file with .json extension and specify that file name as last parameter of AT+S.HTTPPOST command.
Regards,
Elio2018-05-17 04:49 AM
Hi Elio,
Can you make me an example of a .json file?
it is like :
{
'identifier':'centralina',
'password':'password'
}
?
And the json file has to be saved in the WIFI module ? if it's so can you explain me how ?
2018-05-17 07:04 AM
Hi,
it's a regular text file containing JSON formatted data and named with .json extension.
With your example you can type the following sequence into the serial console and get the data saved into example.json:
AT+S.FSC=example.json,61<CR>{<CR><LF> 'identifier':'centralina',<CR><LF>'password':'password'<CR><LF>}
AT-S.OKNow you can send your JSON object by AT+S.HTTPPOST. The following command send your post request to httpbin server to get it analyzed:
AT+S.HTTPPOST=httpbin.org,/post,,,,,,example.json<CR>
AT-S.Http Server Status Code:200{ 'args':{ }, 'data':'{\r\n \'identifier\':\'centralina\',\r\n \'password\':\'password\'\r\n}', 'files':{ }, 'form':{ }, 'headers':{ 'Connection':'close', 'Content-Type':'application/json', 'Host':'httpbin.org', 'Transfer-Encoding':'chunked', 'User-Agent':'HTTP-Client' }, 'json':{ 'identifier':'centralina', 'password':'password' }, 'origin':'62.110.21.125', 'url':''}AT-S.OK2018-05-18 03:58 AM
Thanks Elio,
but I have another one question:
I have to cennect to a cloud in POST and it send me a token that I have to use into the header of a GET call.
How can I fill the header of my GET call with that token ?
2018-05-18 04:44 AM
AT+S.HTTPGET command does not allow the user to specify 'custom' headers in the request.
You may manually compose you GET request, open a regular TCP or TLS socket to the server (using AT+S.SOCKON), send your request to the server (using AT+S.SOCKW) and read the answer by AT+S.SOCKR.
Please find the details of socket commands in the
.