400 Bad Request "Your browser sent an invalid request"


#1

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}]

#2

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


#3

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}]

#4

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?


#5

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.


#6

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.