400 Bad Request "Your browser sent an invalid request"

I’m using the Mbed NXP LPC1768 controller with ESP8266. I’m able to send one value to one variable. When I try to send the multiple value to multiple variable, Im getting the 400 Bad Request Error, “Your browser sent an invalid request”.

sprintf((char *)str, "[{\"variable\": \"5a0d4bcbc03f971c35ce0f31\", \"value\":41}, {\"variable\": \"5a0d4dd5c03f971fd8626f00\", \"value\":88}]");
printf("%s\r\n", str);
int len = strlen((char *)str);
sprintf((char *)http_cmd,"POST /api/v1.6/collections/values/?token=A1E-81jrHpJo3W2EVnhYspewghv89eNA1P 
HTTP/1.1\r\nHost: things.ubidots.com\r\nContent-Type: application/json\r\nContent-Length: %d\r\n\r\n%s\r\n\r\n",
len, str);
pc.printf(http_cmd);

The content it print out to send is:

POST /api/v1.6/collections/values/?token=A1E-81jrHpJo3W2EVnhYspewghv89eNA1P HTTP/1.1
Host: things.ubidots.com
Content-Type: application/json
Content-Length: 108

[{"variable": "5a0d4bcbc03f971c35ce0f31", "value":41}, {"variable": "5a0d4dd5c03f971fd8626f00", "value":88}]

Greetings @jynhao94, I am not sure what your error is, I see that you built properly the payload. Try to send one single value inside your payload and look if you still get a 400 request

If i send this one, its work.

POST /api/v1.6/collections/values/?token=A1E-81jrHpJo3W2EVnhYspewghv89eNA1P HTTP/1.1
Host: things.ubidots.com
Content-Type: application/json
Content-Length: 56

[{"variable": "5a0d4bcbc03f971c35ce0f31", "value":41.2}]

but when i try to send this one with the same code, it doesn’t work.

  POST /api/v1.6/collections/values/?token=A1E-81jrHpJo3W2EVnhYspewghv89eNA1P HTTP/1.1
  Host: things.ubidots.com
  Content-Type: application/json
  Content-Length: 108

  [{"variable": "5a0d4bcbc03f971c35ce0f31", "value":41.2}, {"variable": "5a0d4dd5c03f971fd8626f00", "value":88.2}]

The content-length of this payload :

[{"variable": "5a0d4bcbc03f971c35ce0f31", "value":41.2}]

seems to be 56, but the content-length of this one

[{"variable": "5a0d4bcbc03f971c35ce0f31", "value":41.2}, {"variable": "5a0d4dd5c03f971fd8626f00", "value":88.2}]

seems to be 112 instead of 108, can you check?

Oh ya, that was my mistake in last post, so this is now I’m going to send. But it is still not working.

POST /api/v1.6/collections/values/?token=A1E-81jrHpJo3W2EVnhYspewghv89eNA1P HTTP/1.1
Host: things.ubidots.com
Content-Type: application/json
Content-Length: 112

[{"variable": "5a0d4bcbc03f971c35ce0f31", "value":41.2}, {"variable": "5a0d4dd5c03f971fd8626f00", "value":41.2}]

I’m using AT+CIPSEND command to send.
the AT+CIPSEND=283 was send but there is no response.

POST /api/v1.6/collections/values/?token=A1E-81jrHpJo3W2EVnhYspewghv89eNA1P HTTP/1.1
Host: things.ubidots.com
Content-Type: application/json
Content-Length: 56

[{"variable": "5a0d4bcbc03f971c35ce0f31", "value":41.2}]

if I’m using this one, the AT+CIPSEND=226 was send. This make my value sent to variable.

I’m getting this response.

400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.

Returning 400 means that the request was malformed. In other words, the data stream sent by the client to the server didn’t follow the rules. The client SHOULD NOT repeat the request without modifications. It means that the request itself has somehow incorrect or corrupted and the server couldn’t understand it. The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method . Therefore, it prevents the website from being properly displayed. To fix a 400 Bad Request error, it is best to start diagnosing the issue from the client side itself. Complete the steps outlined in this section to help diagnose and correct the error.

  • Check for errors in the URL.
  • Clear Browser Cache and cookies.
  • Clear DNS Cache.
  • Check your File upload Size.
  • Deactivate Browser Extensions.