What's wrong with my HTTP request?

Started by wispy__sun__266

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!

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.

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

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.

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"}";