HTTP Request library for Arduino and the ESP8266 WiFi SOC modules
This library now supports SSL! To use with SSL, you need to include the SHA1 fingerprint of the certificate of the site you are connecting to. You can get this by using a desktop browser and inspecting the SSL cert used at the site. Please note: this is FRAGILE, if the site updates their SSL, your code will break. But, there is not enough memory on the ESP8266 to store all the rool certs, so this is a working method. Se the example below.
This library is derived almost entirely from the great work done here: https://github.com/csquared/arduino-restclient
Clone (or download and unzip) the repository to ~/Documents/Arduino/libraries
where ~/Documents/Arduino
is your sketchbook directory.
> cd ~/Documents/Arduino
> mkdir libraries
> cd libraries
> git clone https://github.com/dakaz/esp8266-restclient.git RestClient
You need to have the ESP8266
board support already included.
Constructor to create an RestClient object to make requests against.
Use domain name and default to port 80:
RestClient client = RestClient("arduino-http-lib-test.herokuapp.com");
Use a local IP and an explicit port:
RestClient client = RestClient("192.168.1.50",5000);
Use a local IP, an explicit port to an SSL site and (must include the 1 to turn on SSL):
RestClient client = RestClient("www.kudoso.com",443, 1);
Use a local IP, an explicit port to an SSL site and verify the certificate with its fingerprint:
RestClient client = RestClient("www.kudoso.com",443, "EE 16 77 79 55 58 92 46 FB 18 40 99 2E 17 7E AB 32 0A 4A 88");
Sets up EthernetClient
with a mac address of DEADBEEFFEED
. Returns true
or false
to indicate if setting up DHCP
was successful or not
All methods return an HTTP status code or 0 if there was an error.
Start making requests!
int statusCode = client.get("/"));
Pass in a string by reference for the response:
String response = "";
int statusCode = client.get("/", &response);
String response = "";
int statusCode = client.post("/", &response);
statusCode = client.post("/", "foo=bar");
response = "";
statusCode = client.post("/", "foo=bar", &response);
String response = "";
int statusCode = client.put("/", &response);
statusCode = client.put("/", "foo=bar");
response = "";
statusCode = client.put("/", "foo=bar", &response);
String response = "";
int statusCode = client.del("/", &response);
I test every way of calling the library (against a public heroku app)[https://github.com/csquared/arduino-http-test].
You can find the file in File->Examples->RestClient->full_test_suite
If you're having trouble, you can always open RestClient.cpp
and throw at the top:
#define HTTP_DEBUG
Everything happening in the client will get printed to the Serial port.
ricardochimal For all his c++ help. Couldn't have done this without you!
theycallmeswift Helping incept and debug v1.0