What's wrong with my HTTP request?

Started by wispy__sun__266
3b51d732d94baa3d5b80a6a5872e6bff?s=128&d=mm

wispy__sun__266

Dear community,

I can't seem to manage to get a PUT request through. Is there something wrong with my HTTP request?
See below –
const char *httpRequest = "PUT /api/v1/WYqerH2M8Tzpg5aqWhRsdRxNoRzQURS0/state\n"
"Content-Type: application/json\n"
"Content-Length: 21\n"
"{"select" : "Forest"}";

Appreciate your help, cheers!

C39416f4bdabbd5010f596095fb24348?s=128&d=mm

Aliakbar Eski

Hi @wispy__sun__266

You should have a \r\n after each header.
Also if you want to change the current effect to Forest, you have to write to the /effects endpoint, and not the /state endpoint.

Hopefully this should get you up and running with the API.

0cf42d02f6a7d36f678efd111193855e?s=128&d=mm

rough__snowflake__557

Cheers Alikbar

So the request should look like this?
const char *httpRequest = "PUT /api/v1/WYqerH2M8Tzpg5aqWhRsdRxNoRzQURS0/effects\r\n"
"Content-Type: application/json\r\n"
"Content-Length: 21\r\n"
"{"select" : "Forest"}";

Thanks Again

3b51d732d94baa3d5b80a6a5872e6bff?s=128&d=mm

wispy__sun__266

Hey Alia,

Witht the following
const char *httpRequest = "PUT /api/v1/WYqerH2M8Tzpg5aqWhRsdRxNoRzQURS0/effects\r\n"
"Content-Type: application/json\r\n"
"Content-Length: 21\r\n"
"{"select" : "Forest"}";

It just sends the PUT request and then stalls. No HTTP reply from Nanoleaf.

C39416f4bdabbd5010f596095fb24348?s=128&d=mm

Aliakbar Eski

Hey @wispy__sun__266

You need an extra \r\n between your body and headers.

So your request should be like:

const char *httpRequest = "PUT /api/v1/WYqerH2M8Tzpg5aqWhRsdRxNoRzQURS0/effects\r\n"
"Content-Type: application/json\r\n"
"Content-Length: 21\r\n\r\n"
"{"select" : "Forest"}";

3b51d732d94baa3d5b80a6a5872e6bff?s=128&d=mm

wispy__sun__266

Wow, it worked! Thank you so much!
How did you know?

3b51d732d94baa3d5b80a6a5872e6bff?s=128&d=mm

wispy__sun__266

Oh damn, I really don't do enough socket programming.. (namely HTTP)
Cheers though!