Hi,
I need some help with a really basic POST-Request. I´m using the following code (based on some examples):
TCPClient client;
byte server[] = { 192, 168, 178, 28 };
void setup() {
Serial.begin(9600);
while(!Serial.available());
delay(500);
Serial.println("go, go, go...");
if (client.connect(server, 1400)) {
Serial.println("connected...");
client.println("POST /DoATest HTTP/1.0");
client.println("test"); //does not work
client.println();
delay(250);
Serial.println("request sent...");
}
else {
Serial.println("connection failed");
}
}
void loop() {
if (client.available()) {
Serial.print( (char) client.read() );
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(1000);
}
}
Now here is the problem: I´m not able to receive the message-body (“test”).
I get the first line with a simple server (see last part) and the headers, but the body will be lost.
If I change the lines to (according to some example for arduino and this forum)
client.println("POST /DoATest HTTP/1.0");
client.println();
client.println("test"); //does not work
the request will never be sent.
After hours of testing and changing I had one version that works correct, but after some more changes it didn´t work again and the old version was lost. What am I doing wrong?
For my project I need to send xml data in the body. But I am far away, if I cannot send ‘test’…
Simple nodeJS-Server to check and monitor POST-Requests:
var http = require('http');
http.createServer(function (req, res) {
console.log("\n\n");
console.log(req.method + " " + req.url + " " + req.httpVersion);
console.log(req.headers);
if(req.method == 'POST') {
req.on('data', function(chunk) {
console.log(chunk.toString());
});
}
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1400);
console.log('Server running...');
Thanks for your help…