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!
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.
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
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.
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"}";
Wow, it worked! Thank you so much!
How did you know?
Its part of the HTTP specification :P
Oh damn, I really don't do enough socket programming.. (namely HTTP)
Cheers though!