2
\$\begingroup\$

I am interested in using an ESP8266 to power a physical interface for a network connected device. The device itself supports REST commands, but I am not quite sure how to send PUT requests from the ESP8266. Right now, I am able to use the device's web debugging interface to send REST commands, but I am not sure how I would translate that to the ESP8266.

Using a web browser, I am able to GET information by browsing to

<DEVICE_IP>/API/<USER_ID>/<RESOURCE>

but I can only get the current state of that resource by navigating to that URL. How would I send a PUT request?

asked Jan 27, 2017 at 2:42
\$\endgroup\$
1
  • \$\begingroup\$ Maybe http.sendRequest("PUT", dataptr, len); if you're using Arduino? \$\endgroup\$ Commented Jan 28, 2017 at 3:04

1 Answer 1

1
\$\begingroup\$

After reading a short tutorial on the ESP8266 module using the Arduino API, I found that replacing the "GET" string with a "PUT" string with the command following. Specifically, to send the command

{"on": true}

to the resource at

/state

The ESP8266 would execute:

String command = "{\"on\": true}";
client.print(String("PUT ") + "/state" + "HTTP/1.1 \r\n" + 
 "Host: " + hosturl + "\r\n" +
 "Content-Length: " + command.length() + "\r\n" +
 "Content-Type: text/plain;charset=UTF-8\r\n\r\n" +
 command + "\r\n" +
 "Connection: close\r\n\r\n");

Honestly, I have very little idea why the "Host," "Content-Length," or "Content-Type" (or even "Connection") are there, but this isn't a MWE, just a WE.

answered Feb 1, 2017 at 6:45
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.