Hello, I am trying to send data from my arduino via SIM900 in form of JSON to database. I am getting response SEND OK but no data is received on server side.
Data is a string formated as json with data for my database.
String data= "{"a": 1000, "b": 1000, "c": 1000, "d": 1000, "e": 1000, "f": 1000, "g": 1000, "h": 1000, "i": 1000}";
I think there might be something wrong with my header, everything else works, there are no error responses.
client.print("POST /writedata HTTP/1.1\r\n");
client.print("Host: adressofmyapi.com\r\n");
client.print("Cache-Control: no-cache\r\n");
client.print("Content-Type: application/json\r\n\r\n");
client.println(data);
client.print((char)26);
For comparison this is working header from postman:
POST /writedata HTTP/1.1
Host: adressofmyapi.com
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: token
{"a": 1, "b": 1, "c": 1,"d": 1,"e": 1,"f": 1,"g": 1, "h": 1,"i": 1}
On server side I have simple JavaScript Express application.
app.post('/writedata',jsonParser, function(req,res){
var post = req.body;
var query = connection.query('INSERT INTO database SET ?', post, function (error, results, fields) {
});
});
Any help would be appreciated.