I am working with an Arduino Mega and a SIM900 GSM/GPRS shield to make a get request against my own API.
I am using the following AT Commands, the module executes the request, but I receive a 200 response code without a body/response.
Here is my code:
AT+SAPBR=3,1,"Contype","GPRS"
AT+SAPBR=3,1,"APN","my.apn.com"
AT+SAPBR=1,1
AT+SAPBR=2,1
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","wbs-api.eu-gb.cf.appdomain.cloud/stats"
AT+HTTPACTION=0
-> 0,200,0 (as output of the command)
As far as I know, the last 0 stands for the size of the response body in bytes.
If I further execute
AT+HTTPREAD
->
Nothing is displayed.
Where has my answer disappeared to and why is it empty?
Note: I'm actually able to successful obtain data performing a request to a different server, but I noticed that the working request returns HTML code and not JSON data.
Configure the accepted content type with
AT+HTTPPARA="CONTENT","application/json"
Since you are admittedly able to receive data from different sites, it means that the issue must be something specific to the address you are accessing.
The difference actually resides in the application type, as you are downloading JSON data. The following image shows the Wireshark capture of the response got from the server:
Content-type: application/json
But was the request some way "special"? The following image shows the Wireshark capture of the request sent to the server from my browser:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n
So we can understand how that's probably a matter of accepted type.
The command for specifying HTTP parameters in Simcom modules (see Simcom AT Commands guide) is AT+HTTPPARA
, that you already use in your script. Its syntax is
AT+HTTPPARA=<HTTPParamTag>,<HTTPParamValue>[<UserdataDelimiter>]
There are several allowed values for HTTPParamTag
parameter, but one of the options is
"CONTENT"
Used to set the “Content-Type” field in HTTP header
For this reason the command
AT+HTTPPARA="CONTENT","application/json"
should make the trick. Just make sure that your FW version supports it. If not, update the FW version to the most recent one.