mirror of
https://github.com/arduino-libraries/ArduinoHttpClient.git
synced 2025-04-19 21:22:15 +03:00
Updated examples and readme.md
This commit is contained in:
parent
b6424e430d
commit
5e1f1f21bf
@ -7,6 +7,7 @@ Derived from [Adrian McEwen's HttpClient library](https://github.com/amcewen/Htt
|
||||
## Dependencies
|
||||
|
||||
- Requires a networking hardware and a library that provides transport specific `Client` instance, such as:
|
||||
- [WiFiNINA](https://github.com/arduino-libraries/WiFiNINA)
|
||||
- [WiFi101](https://github.com/arduino-libraries/WiFi101)
|
||||
- [Ethernet](https://github.com/arduino-libraries/Ethernet)
|
||||
- [WiFi](https://github.com/arduino-libraries/WiFi)
|
||||
|
@ -2,12 +2,12 @@
|
||||
GET client with HTTP basic authentication for ArduinoHttpClient library
|
||||
Connects to server once every five seconds, sends a GET request
|
||||
|
||||
|
||||
|
||||
created 14 Feb 2016
|
||||
by Tom Igoe
|
||||
modified 3 Jan 2017 to add HTTP basic authentication
|
||||
by Sandeep Mistry
|
||||
modified 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
*/
|
||||
@ -25,8 +25,6 @@ int port = 8080;
|
||||
WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
String response;
|
||||
int statusCode = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@ -56,8 +54,8 @@ void loop() {
|
||||
client.endRequest();
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
int statusCode = client.responseStatusCode();
|
||||
String response = client.responseBody();
|
||||
|
||||
Serial.print("Status code: ");
|
||||
Serial.println(statusCode);
|
||||
@ -66,4 +64,3 @@ void loop() {
|
||||
Serial.println("Wait five seconds");
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
@ -2,17 +2,13 @@
|
||||
Custom request header example for the ArduinoHttpClient
|
||||
library. This example sends a GET and a POST request with a custom header every 5 seconds.
|
||||
|
||||
note: WiFi SSID and password are stored in config.h file.
|
||||
If it is not present, add a new tab, call it "config.h"
|
||||
and add the following variables:
|
||||
char ssid[] = "ssid"; // your network SSID (name)
|
||||
char pass[] = "password"; // your network password
|
||||
|
||||
based on SimpleGet example by Tom Igoe
|
||||
header modifications by Todd Treece
|
||||
modified 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <ArduinoHttpClient.h>
|
||||
#include <WiFi101.h>
|
||||
@ -29,8 +25,6 @@ int port = 8080;
|
||||
WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
String response;
|
||||
int statusCode = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@ -53,7 +47,6 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Serial.println("making GET request");
|
||||
client.beginRequest();
|
||||
client.get("/");
|
||||
@ -61,8 +54,8 @@ void loop() {
|
||||
client.endRequest();
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
int statusCode = client.responseStatusCode();
|
||||
String response = client.responseBody();
|
||||
|
||||
Serial.print("GET Status code: ");
|
||||
Serial.println(statusCode);
|
||||
@ -81,6 +74,8 @@ void loop() {
|
||||
client.sendHeader("X-CUSTOM-HEADER", "custom_value");
|
||||
client.endRequest();
|
||||
client.write((const byte*)postData.c_str(), postData.length());
|
||||
// note: the above line can also be achieved with the simpler line below:
|
||||
//client.print(postData);
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
|
@ -9,10 +9,8 @@
|
||||
|
||||
For more on dweet.io, see https://dweet.io/play/
|
||||
|
||||
|
||||
|
||||
created 15 Feb 2016
|
||||
updated 16 Feb 2016
|
||||
updated 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
@ -33,8 +31,6 @@ String dweetName = "scandalous-cheese-hoarder"; // use your own thing name here
|
||||
WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
int statusCode = 0;
|
||||
String response;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@ -66,8 +62,8 @@ void loop() {
|
||||
client.get(path);
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
int statusCode = client.responseStatusCode();
|
||||
String response = client.responseBody();
|
||||
Serial.print("Status code: ");
|
||||
Serial.println(statusCode);
|
||||
Serial.print("Response: ");
|
||||
|
@ -5,13 +5,8 @@
|
||||
|
||||
Shows how to use Strings to assemble path and body
|
||||
|
||||
note: WiFi SSID and password are stored in config.h file.
|
||||
If it is not present, add a new tab, call it "config.h"
|
||||
and add the following variables:
|
||||
char ssid[] = "ssid"; // your network SSID (name)
|
||||
char pass[] = "password"; // your network password
|
||||
|
||||
created 15 Feb 2016
|
||||
modified 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
@ -31,8 +26,6 @@ int port = 80;
|
||||
WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
int statusCode = 0;
|
||||
String response;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@ -59,7 +52,6 @@ void loop() {
|
||||
// assemble the path for the POST message:
|
||||
String dweetName = "scandalous-cheese-hoarder";
|
||||
String path = "/dweet/for/" + dweetName;
|
||||
|
||||
String contentType = "application/json";
|
||||
|
||||
// assemble the body of the POST message:
|
||||
@ -74,8 +66,8 @@ void loop() {
|
||||
client.post(path, contentType, postData);
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
int statusCode = client.responseStatusCode();
|
||||
String response = client.responseBody();
|
||||
|
||||
Serial.print("Status code: ");
|
||||
Serial.println(statusCode);
|
||||
|
@ -13,8 +13,6 @@
|
||||
This example shows how to concatenate Strings to assemble the
|
||||
PUT request and the body of the request.
|
||||
|
||||
|
||||
|
||||
modified 15 Feb 2016
|
||||
by Tom Igoe (tigoe) to match new API
|
||||
*/
|
||||
@ -98,5 +96,3 @@ void sendRequest(int light, String cmd, String value) {
|
||||
Serial.println(response);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,12 +3,12 @@
|
||||
Connects to server once every five seconds, sends a POST request
|
||||
with custome headers and a request body
|
||||
|
||||
|
||||
|
||||
created 14 Feb 2016
|
||||
by Tom Igoe
|
||||
modified 18 Mar 2017
|
||||
by Sandeep Mistry
|
||||
modified 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
*/
|
||||
@ -29,8 +29,6 @@ int port = 8080;
|
||||
WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
String response;
|
||||
int statusCode = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@ -66,8 +64,8 @@ void loop() {
|
||||
client.endRequest();
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
int statusCode = client.responseStatusCode();
|
||||
String response = client.responseBody();
|
||||
|
||||
Serial.print("Status code: ");
|
||||
Serial.println(statusCode);
|
||||
|
@ -3,9 +3,8 @@
|
||||
Connects to server once every five seconds, sends a DELETE request
|
||||
and a request body
|
||||
|
||||
|
||||
|
||||
created 14 Feb 2016
|
||||
modified 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
@ -27,8 +26,6 @@ int port = 8080;
|
||||
WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
String response;
|
||||
int statusCode = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@ -58,8 +55,8 @@ void loop() {
|
||||
client.del("/", contentType, delData);
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
int statusCode = client.responseStatusCode();
|
||||
String response = client.responseBody();
|
||||
|
||||
Serial.print("Status code: ");
|
||||
Serial.println(statusCode);
|
||||
|
@ -2,9 +2,8 @@
|
||||
Simple GET client for ArduinoHttpClient library
|
||||
Connects to server once every five seconds, sends a GET request
|
||||
|
||||
|
||||
|
||||
created 14 Feb 2016
|
||||
modified 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
@ -19,15 +18,12 @@
|
||||
char ssid[] = SECRET_SSID;
|
||||
char pass[] = SECRET_PASS;
|
||||
|
||||
|
||||
char serverAddress[] = "192.168.0.3"; // server address
|
||||
int port = 8080;
|
||||
|
||||
WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
String response;
|
||||
int statusCode = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@ -54,8 +50,8 @@ void loop() {
|
||||
client.get("/");
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
int statusCode = client.responseStatusCode();
|
||||
String response = client.responseBody();
|
||||
|
||||
Serial.print("Status code: ");
|
||||
Serial.println(statusCode);
|
||||
|
@ -3,9 +3,8 @@
|
||||
Connects to server once every five seconds, sends a POST request
|
||||
and a request body
|
||||
|
||||
|
||||
|
||||
created 14 Feb 2016
|
||||
modified 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
@ -19,15 +18,12 @@
|
||||
char ssid[] = SECRET_SSID;
|
||||
char pass[] = SECRET_PASS;
|
||||
|
||||
|
||||
char serverAddress[] = "192.168.0.3"; // server address
|
||||
int port = 8080;
|
||||
|
||||
WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
String response;
|
||||
int statusCode = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@ -57,8 +53,8 @@ void loop() {
|
||||
client.post("/", contentType, postData);
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
int statusCode = client.responseStatusCode();
|
||||
String response = client.responseBody();
|
||||
|
||||
Serial.print("Status code: ");
|
||||
Serial.println(statusCode);
|
||||
|
@ -3,9 +3,8 @@
|
||||
Connects to server once every five seconds, sends a PUT request
|
||||
and a request body
|
||||
|
||||
|
||||
|
||||
created 14 Feb 2016
|
||||
modified 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
@ -19,15 +18,12 @@
|
||||
char ssid[] = SECRET_SSID;
|
||||
char pass[] = SECRET_PASS;
|
||||
|
||||
|
||||
char serverAddress[] = "192.168.0.3"; // server address
|
||||
int port = 8080;
|
||||
|
||||
WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
String response;
|
||||
int statusCode = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@ -57,8 +53,8 @@ void loop() {
|
||||
client.put("/", contentType, putData);
|
||||
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
int statusCode = client.responseStatusCode();
|
||||
String response = client.responseBody();
|
||||
|
||||
Serial.print("Status code: ");
|
||||
Serial.println(statusCode);
|
||||
|
@ -3,9 +3,10 @@
|
||||
Connects to the WebSocket server, and sends a hello
|
||||
message every 5 seconds
|
||||
|
||||
|
||||
created 28 Jun 2016
|
||||
by Sandeep Mistry
|
||||
modified 22 Jan 2019
|
||||
by Tom Igoe
|
||||
|
||||
this example is in the public domain
|
||||
*/
|
||||
@ -77,4 +78,3 @@ void loop() {
|
||||
|
||||
Serial.println("disconnected");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user