Search code examples
posthttp-status-code-400arduino-esp8266

POST request does not work on external servers


I am trying to send data from an arduino to a web server (LAMP) using the ESP8266 module, when I do a POST to a local network server the server receives the data and returns 200, however, when I post to an external server (Hosting or google cloud) it registers error 400 in the Apache log and returns nothing, but when I do the same type of request by Postman everything is fine, because of this I do not know if it is my fault when mounting or executing the request or if Is some block on the external servers because the http server in my network works.

I'm using this lib to work with ESP: https://github.com/itead/ITEADLIB_Arduino_WeeESP8266

This is the request string:

POST /data/sensor_test.php HTTP/1.1
Host: xxxxxxxxx.com
Accept: */*
Content-Length: 188
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache

temperatureAir1=19.70&humidityAir1=82.30&temperatureAir2=19.40&humidityAir2=78.60&externalTemperature=19.31&illumination05=898&illumination10=408&humiditySoilXD28=6&humiditySoilYL69=5

Solution

  • I found the problem, when I concatenated the strings that make up the request I was doing line breaks with \n, I switched to \r\n and it worked! The amount of bytes really is with error, I am seeing to correct, but the good thing is that now the request is right.