I need to send simple HTTP POST Request using ESP8266. It's containing data in "form-data".
It should look like this:
POST http://testserver.com
{
"auth_key":"key",
"data":[
{
"key":"humidity",
"value":50
}
]
}
For the testing I was using Chrome application - Postman. And the HTTP Request code which I send was looking like this (it was automatically generated):
POST /api/mes HTTP/1.1
Host: testserver.com
Cache-Control: no-cache
Postman-Token: 9b910ed2-afdc-2a11-4963-2f85626cfa4e
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="auth_key"
79bde0ff1efeaee90b1e432c08d324ecfdb532ac42406d7a9a87dd911e95f87e
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="data"
[{"key":"humidity", "value":55}]
------WebKitFormBoundary7MA4YWxkTrZu0gW--
And through Postman everything was okay. So then I sent it through ESP8266:
client.setNoDelay(true);
client.println("POST /api/mes HTTP/1.1");
client.println("Host: testserver.com");
client.println("Cache-Control: no-cache");
client.println("Postman-Token: 9b910ed2-afdc-2a11-4963-2f85626cfa4e");
client.println("Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
client.println("");
client.println("------WebKitFormBoundary7MA4YWxkTrZu0gW");
client.println("Content-Disposition: form-data; name=\"auth_key\"");
client.println("");
client.println("79bde0ff1efeaee90b1e432c08d324ecfdb532ac42406d7a9a87dd911e95f87e");
client.println("------WebKitFormBoundary7MA4YWxkTrZu0gW");
client.println("Content-Disposition: form-data; name=\"data\"");
client.println("");
client.println("[{\"key\":\"humidity\", \"value\":55}]");
client.println("------WebKitFormBoundary7MA4YWxkTrZu0gW--");
But unfortunately server is returning that the request is not correct. What can cause the problem? I'm struggling with it but I don't have any more ideas.