cancel
Showing results for 
Search instead for 
Did you mean: 

SPWF04Sx HTTPOST command with JSON payload

Andrea Ortogni
Associate II
Posted on May 17, 2018 at 10:27

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-post
5 REPLIES 5
Elio Cometti
Senior II
Posted on May 17, 2018 at 11:27

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,

Elio
Posted on May 17, 2018 at 11:49

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 ?

Posted on May 17, 2018 at 14:04

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.OK

Now 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':'

http://httpbin.org/post

'

}

AT-S.OK
Posted on May 18, 2018 at 10:58

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 ?

Posted on May 18, 2018 at 11:44

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

http://www.st.com/resource/en/user_manual/dm00329655.pdf

.