Hi,
I'm making HTTP POST request to my NODE.JS server. On POST link server is reading body part of request to get data send from my Arduino. When I do request from Postman server is able to get body part. Whole request from Postman looks like this:
POST /channel/59a269e90cd5ee4c84e1555f HTTP/1.1
Host: localhost:3000
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
Postman-Token: c694be6a-5f08-e970-d2cb-4e4ff789f2a5
field1=1
But when Arduino is doing POST request on server I can see that request is done but without body part (on server body part is empty). Code on arduino is :
data.concat("field1=");
data.concat(10);
if(client.connect("192.168.8.101",3000)){
client.println("POST /channel/59a269e90cd5ee4c84e1555f HTTP/1.1");
client.println("Host: localhost:3000");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.println(data);
}
I can't see what I'm doing wrong and I all ready lost few hours to this problem. I'm using Arduino Pro with W5100.
EDIT: It's solved. I was missing this part client.println("Content-Type: application/x-www-form-urlencoded"); . So whole POST request on arduino looks like this :
data.concat("field1=");
data.concat(10);
if(client.connect("192.168.8.101",3000)){
client.println("POST /channel/59a269e90cd5ee4c84e1555f HTTP/1.1");
client.println("Host: localhost:3000");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.println(data);
}
EDIT 2: It's important that headers go in this order and that body is separated from headers with empty line. If I mix order of headers POST request will not work correctly