I have some code that puts together a HTTP POST request with JSON data (GPS coordinates) and updates an IoT database. However, the response "Content-type must be application/json" is returned together with an error every time the request is sent.
So I logged the request with requestcatcher and the HTTP POST request looks like this. As you can see, no content type:
POST / HTTP/1.1
Host: ct.requestcatcher.com
Accept: */*
Connection: Keep-Alive
Content-Length: 42
User-Agent: SIMCOM_MODULE
{"longitude": 40.0015,"latitude": 90.5032}
The Arduino code is as follows:
void postDataThinger(char *httpDataLen, char* content)
{
SIM900.println( F("AT+HTTPINIT") );
delay(1000);
updateSIM900();
SIM900.println( F("AT+HTTPPARA=\"CID\",1") );
delay(1000);
updateSIM900();
SIM900.println( F("AT+HTTPPARA=\"URL\",\"http://ct.requestcatcher.com\"") );
delay(1000);
updateSIM900();
SIM900.println( F("AT+HTTPPARA=\"CONTENT\",\"application/json\"") );
delay(1000);
updateSIM900();
SIM900.println(httpDataLen);
delay(1000);
updateSIM900();
SIM900.println(content);
delay(1000);
updateSIM900();
SIM900.println( F("AT+HTTPACTION=1") );
delay(10000);
updateSIM900();
SIM900.println( F("AT+HTTPREAD"));
delay(2000);
updateSIM900();
SIM900.println( F("AT+HTTPTERM") );
delay(1000);
updateSIM900();
}
I don't understand why this line of code do not work:
SIM900.println( F("AT+HTTPPARA=\"CONTENT\",\"application/json\"") );
The moden returns "OK" for all commands, this is the console output:
AT+HTTPINIT
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPPARA="URL","http://ct.requestcatcher.com"
OK
AT+HTTPPARA="CONTENT","application/json"
OK
AT+HTTPDATA=42,10000
DOWNLOAD
OK
AT+HTTPACTION=1
OK
+HTTPACTION:1,301,0
AT+HTTPREAD
OK
AT+HTTPTERM
OK
Any ideas? I have also tried to replace the mentioned "CONTENT" command with:
AT+HTTPPARA="USERDATA","Content-Type: application/json"
..but this had no effect.