| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b6424e4 commit 5e1f1f2
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ Derived from [Adrian McEwen's HttpClient library](https://github.com/amcewen/Htt | |||
| 7 | 7 | ## Dependencies | |
| 8 | 8 | ||
| 9 | 9 | - Requires a networking hardware and a library that provides transport specific `Client` instance, such as: | |
| 10 | + - [WiFiNINA](https://github.com/arduino-libraries/WiFiNINA) | ||
| 10 | 11 | - [WiFi101](https://github.com/arduino-libraries/WiFi101) | |
| 11 | 12 | - [Ethernet](https://github.com/arduino-libraries/Ethernet) | |
| 12 | 13 | - [WiFi](https://github.com/arduino-libraries/WiFi) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,12 +2,12 @@ | |||
| 2 | 2 | GET client with HTTP basic authentication for ArduinoHttpClient library | |
| 3 | 3 | Connects to server once every five seconds, sends a GET request | |
| 4 | 4 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | 5 | created 14 Feb 2016 | |
| 8 | 6 | by Tom Igoe | |
| 9 | 7 | modified 3 Jan 2017 to add HTTP basic authentication | |
| 10 | 8 | by Sandeep Mistry | |
| 9 | + modified 22 Jan 2019 | ||
| 10 | + by Tom Igoe | ||
| 11 | 11 | ||
| 12 | 12 | this example is in the public domain | |
| 13 | 13 | */ | |
@@ -25,8 +25,6 @@ int port = 8080; | |||
| 25 | 25 | WiFiClient wifi; | |
| 26 | 26 | HttpClient client = HttpClient(wifi, serverAddress, port); | |
| 27 | 27 | int status = WL_IDLE_STATUS; | |
| 28 | - String response; | ||
| 29 | - int statusCode = 0; | ||
| 30 | 28 | ||
| 31 | 29 | void setup() { | |
| 32 | 30 | Serial.begin(9600); | |
@@ -56,8 +54,8 @@ void loop() { | |||
| 56 | 54 | client.endRequest(); | |
| 57 | 55 | ||
| 58 | 56 | // read the status code and body of the response | |
| 59 | - statusCode = client.responseStatusCode(); | ||
| 60 | - response = client.responseBody(); | ||
| 57 | + int statusCode = client.responseStatusCode(); | ||
| 58 | + String response = client.responseBody(); | ||
| 61 | 59 | ||
| 62 | 60 | Serial.print("Status code: "); | |
| 63 | 61 | Serial.println(statusCode); | |
@@ -66,4 +64,3 @@ void loop() { | |||
| 66 | 64 | Serial.println("Wait five seconds"); | |
| 67 | 65 | delay(5000); | |
| 68 | 66 | } | |
| 69 | - | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,18 +2,14 @@ | |||
| 2 | 2 | Custom request header example for the ArduinoHttpClient | |
| 3 | 3 | library. This example sends a GET and a POST request with a custom header every 5 seconds. | |
| 4 | 4 | ||
| 5 | - note: WiFi SSID and password are stored in config.h file. | ||
| 6 | - If it is not present, add a new tab, call it "config.h" | ||
| 7 | - and add the following variables: | ||
| 8 | - char ssid[] = "ssid"; // your network SSID (name) | ||
| 9 | - char pass[] = "password"; // your network password | ||
| 10 | - | ||
| 11 | 5 | based on SimpleGet example by Tom Igoe | |
| 12 | 6 | header modifications by Todd Treece | |
| 7 | + modified 22 Jan 2019 | ||
| 8 | + by Tom Igoe | ||
| 13 | 9 | ||
| 14 | 10 | this example is in the public domain | |
| 15 | - */ | ||
| 16 | - | ||
| 11 | + */ | ||
| 12 | + | ||
| 17 | 13 | #include <ArduinoHttpClient.h> | |
| 18 | 14 | #include <WiFi101.h> | |
| 19 | 15 | ||
@@ -29,8 +25,6 @@ int port = 8080; | |||
| 29 | 25 | WiFiClient wifi; | |
| 30 | 26 | HttpClient client = HttpClient(wifi, serverAddress, port); | |
| 31 | 27 | int status = WL_IDLE_STATUS; | |
| 32 | - String response; | ||
| 33 | - int statusCode = 0; | ||
| 34 | 28 | ||
| 35 | 29 | void setup() { | |
| 36 | 30 | Serial.begin(9600); | |
@@ -53,16 +47,15 @@ void setup() { | |||
| 53 | 47 | } | |
| 54 | 48 | ||
| 55 | 49 | void loop() { | |
| 56 | - | ||
| 57 | 50 | Serial.println("making GET request"); | |
| 58 | 51 | client.beginRequest(); | |
| 59 | 52 | client.get("/"); | |
| 60 | 53 | client.sendHeader("X-CUSTOM-HEADER", "custom_value"); | |
| 61 | 54 | client.endRequest(); | |
| 62 | 55 | ||
| 63 | 56 | // read the status code and body of the response | |
| 64 | - statusCode = client.responseStatusCode(); | ||
| 65 | - response = client.responseBody(); | ||
| 57 | + int statusCode = client.responseStatusCode(); | ||
| 58 | + String response = client.responseBody(); | ||
| 66 | 59 | ||
| 67 | 60 | Serial.print("GET Status code: "); | |
| 68 | 61 | Serial.println(statusCode); | |
@@ -81,6 +74,8 @@ void loop() { | |||
| 81 | 74 | client.sendHeader("X-CUSTOM-HEADER", "custom_value"); | |
| 82 | 75 | client.endRequest(); | |
| 83 | 76 | client.write((const byte*)postData.c_str(), postData.length()); | |
| 77 | + // note: the above line can also be achieved with the simpler line below: | ||
| 78 | + //client.print(postData); | ||
| 84 | 79 | ||
| 85 | 80 | // read the status code and body of the response | |
| 86 | 81 | statusCode = client.responseStatusCode(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,10 +9,8 @@ | |||
| 9 | 9 | ||
| 10 | 10 | For more on dweet.io, see https://dweet.io/play/ | |
| 11 | 11 | ||
| 12 | - | ||
| 13 | - | ||
| 14 | 12 | created 15 Feb 2016 | |
| 15 | - updated 16 Feb 2016 | ||
| 13 | + updated 22 Jan 2019 | ||
| 16 | 14 | by Tom Igoe | |
| 17 | 15 | ||
| 18 | 16 | this example is in the public domain | |
@@ -33,8 +31,6 @@ String dweetName = "scandalous-cheese-hoarder"; // use your own thing name here | |||
| 33 | 31 | WiFiClient wifi; | |
| 34 | 32 | HttpClient client = HttpClient(wifi, serverAddress, port); | |
| 35 | 33 | int status = WL_IDLE_STATUS; | |
| 36 | - int statusCode = 0; | ||
| 37 | - String response; | ||
| 38 | 34 | ||
| 39 | 35 | void setup() { | |
| 40 | 36 | Serial.begin(9600); | |
@@ -66,8 +62,8 @@ void loop() { | |||
| 66 | 62 | client.get(path); | |
| 67 | 63 | ||
| 68 | 64 | // read the status code and body of the response | |
| 69 | - statusCode = client.responseStatusCode(); | ||
| 70 | - response = client.responseBody(); | ||
| 65 | + int statusCode = client.responseStatusCode(); | ||
| 66 | + String response = client.responseBody(); | ||
| 71 | 67 | Serial.print("Status code: "); | |
| 72 | 68 | Serial.println(statusCode); | |
| 73 | 69 | Serial.print("Response: "); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,13 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | 6 | Shows how to use Strings to assemble path and body | |
| 7 | 7 | ||
| 8 | - note: WiFi SSID and password are stored in config.h file. | ||
| 9 | - If it is not present, add a new tab, call it "config.h" | ||
| 10 | - and add the following variables: | ||
| 11 | - char ssid[] = "ssid"; // your network SSID (name) | ||
| 12 | - char pass[] = "password"; // your network password | ||
| 13 | - | ||
| 14 | 8 | created 15 Feb 2016 | |
| 9 | + modified 22 Jan 2019 | ||
| 15 | 10 | by Tom Igoe | |
| 16 | 11 | ||
| 17 | 12 | this example is in the public domain | |
@@ -31,8 +26,6 @@ int port = 80; | |||
| 31 | 26 | WiFiClient wifi; | |
| 32 | 27 | HttpClient client = HttpClient(wifi, serverAddress, port); | |
| 33 | 28 | int status = WL_IDLE_STATUS; | |
| 34 | - int statusCode = 0; | ||
| 35 | - String response; | ||
| 36 | 29 | ||
| 37 | 30 | void setup() { | |
| 38 | 31 | Serial.begin(9600); | |
@@ -59,7 +52,6 @@ void loop() { | |||
| 59 | 52 | // assemble the path for the POST message: | |
| 60 | 53 | String dweetName = "scandalous-cheese-hoarder"; | |
| 61 | 54 | String path = "/dweet/for/" + dweetName; | |
| 62 | - | ||
| 63 | 55 | String contentType = "application/json"; | |
| 64 | 56 | ||
| 65 | 57 | // assemble the body of the POST message: | |
@@ -74,8 +66,8 @@ void loop() { | |||
| 74 | 66 | client.post(path, contentType, postData); | |
| 75 | 67 | ||
| 76 | 68 | // read the status code and body of the response | |
| 77 | - statusCode = client.responseStatusCode(); | ||
| 78 | - response = client.responseBody(); | ||
| 69 | + int statusCode = client.responseStatusCode(); | ||
| 70 | + String response = client.responseBody(); | ||
| 79 | 71 | ||
| 80 | 72 | Serial.print("Status code: "); | |
| 81 | 73 | Serial.println(statusCode); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,8 +13,6 @@ | |||
| 13 | 13 | This example shows how to concatenate Strings to assemble the | |
| 14 | 14 | PUT request and the body of the request. | |
| 15 | 15 | ||
| 16 | - | ||
| 17 | - | ||
| 18 | 16 | modified 15 Feb 2016 | |
| 19 | 17 | by Tom Igoe (tigoe) to match new API | |
| 20 | 18 | */ | |
@@ -97,6 +95,4 @@ void sendRequest(int light, String cmd, String value) { | |||
| 97 | 95 | Serial.print("Server response: "); | |
| 98 | 96 | Serial.println(response); | |
| 99 | 97 | Serial.println(); | |
| 100 | - } | ||
| 101 | - | ||
| 102 | - | ||
| 98 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,12 +3,12 @@ | |||
| 3 | 3 | Connects to server once every five seconds, sends a POST request | |
| 4 | 4 | with custome headers and a request body | |
| 5 | 5 | ||
| 6 | - | ||
| 7 | - | ||
| 8 | 6 | created 14 Feb 2016 | |
| 9 | 7 | by Tom Igoe | |
| 10 | 8 | modified 18 Mar 2017 | |
| 11 | 9 | by Sandeep Mistry | |
| 10 | + modified 22 Jan 2019 | ||
| 11 | + by Tom Igoe | ||
| 12 | 12 | ||
| 13 | 13 | this example is in the public domain | |
| 14 | 14 | */ | |
@@ -29,8 +29,6 @@ int port = 8080; | |||
| 29 | 29 | WiFiClient wifi; | |
| 30 | 30 | HttpClient client = HttpClient(wifi, serverAddress, port); | |
| 31 | 31 | int status = WL_IDLE_STATUS; | |
| 32 | - String response; | ||
| 33 | - int statusCode = 0; | ||
| 34 | 32 | ||
| 35 | 33 | void setup() { | |
| 36 | 34 | Serial.begin(9600); | |
@@ -66,8 +64,8 @@ void loop() { | |||
| 66 | 64 | client.endRequest(); | |
| 67 | 65 | ||
| 68 | 66 | // read the status code and body of the response | |
| 69 | - statusCode = client.responseStatusCode(); | ||
| 70 | - response = client.responseBody(); | ||
| 67 | + int statusCode = client.responseStatusCode(); | ||
| 68 | + String response = client.responseBody(); | ||
| 71 | 69 | ||
| 72 | 70 | Serial.print("Status code: "); | |
| 73 | 71 | Serial.println(statusCode); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,9 +3,8 @@ | |||
| 3 | 3 | Connects to server once every five seconds, sends a DELETE request | |
| 4 | 4 | and a request body | |
| 5 | 5 | ||
| 6 | - | ||
| 7 | - | ||
| 8 | 6 | created 14 Feb 2016 | |
| 7 | + modified 22 Jan 2019 | ||
| 9 | 8 | by Tom Igoe | |
| 10 | 9 | ||
| 11 | 10 | this example is in the public domain | |
@@ -27,8 +26,6 @@ int port = 8080; | |||
| 27 | 26 | WiFiClient wifi; | |
| 28 | 27 | HttpClient client = HttpClient(wifi, serverAddress, port); | |
| 29 | 28 | int status = WL_IDLE_STATUS; | |
| 30 | - String response; | ||
| 31 | - int statusCode = 0; | ||
| 32 | 29 | ||
| 33 | 30 | void setup() { | |
| 34 | 31 | Serial.begin(9600); | |
@@ -58,8 +55,8 @@ void loop() { | |||
| 58 | 55 | client.del("/", contentType, delData); | |
| 59 | 56 | ||
| 60 | 57 | // read the status code and body of the response | |
| 61 | - statusCode = client.responseStatusCode(); | ||
| 62 | - response = client.responseBody(); | ||
| 58 | + int statusCode = client.responseStatusCode(); | ||
| 59 | + String response = client.responseBody(); | ||
| 63 | 60 | ||
| 64 | 61 | Serial.print("Status code: "); | |
| 65 | 62 | Serial.println(statusCode); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,9 +2,8 @@ | |||
| 2 | 2 | Simple GET client for ArduinoHttpClient library | |
| 3 | 3 | Connects to server once every five seconds, sends a GET request | |
| 4 | 4 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | 5 | created 14 Feb 2016 | |
| 6 | + modified 22 Jan 2019 | ||
| 8 | 7 | by Tom Igoe | |
| 9 | 8 | ||
| 10 | 9 | this example is in the public domain | |
@@ -19,15 +18,12 @@ | |||
| 19 | 18 | char ssid[] = SECRET_SSID; | |
| 20 | 19 | char pass[] = SECRET_PASS; | |
| 21 | 20 | ||
| 22 | - | ||
| 23 | 21 | char serverAddress[] = "192.168.0.3"; // server address | |
| 24 | 22 | int port = 8080; | |
| 25 | 23 | ||
| 26 | 24 | WiFiClient wifi; | |
| 27 | 25 | HttpClient client = HttpClient(wifi, serverAddress, port); | |
| 28 | 26 | int status = WL_IDLE_STATUS; | |
| 29 | - String response; | ||
| 30 | - int statusCode = 0; | ||
| 31 | 27 | ||
| 32 | 28 | void setup() { | |
| 33 | 29 | Serial.begin(9600); | |
@@ -54,8 +50,8 @@ void loop() { | |||
| 54 | 50 | client.get("/"); | |
| 55 | 51 | ||
| 56 | 52 | // read the status code and body of the response | |
| 57 | - statusCode = client.responseStatusCode(); | ||
| 58 | - response = client.responseBody(); | ||
| 53 | + int statusCode = client.responseStatusCode(); | ||
| 54 | + String response = client.responseBody(); | ||
| 59 | 55 | ||
| 60 | 56 | Serial.print("Status code: "); | |
| 61 | 57 | Serial.println(statusCode); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,9 +3,8 @@ | |||
| 3 | 3 | Connects to server once every five seconds, sends a POST request | |
| 4 | 4 | and a request body | |
| 5 | 5 | ||
| 6 | - | ||
| 7 | - | ||
| 8 | 6 | created 14 Feb 2016 | |
| 7 | + modified 22 Jan 2019 | ||
| 9 | 8 | by Tom Igoe | |
| 10 | 9 | ||
| 11 | 10 | this example is in the public domain | |
@@ -19,15 +18,12 @@ | |||
| 19 | 18 | char ssid[] = SECRET_SSID; | |
| 20 | 19 | char pass[] = SECRET_PASS; | |
| 21 | 20 | ||
| 22 | - | ||
| 23 | 21 | char serverAddress[] = "192.168.0.3"; // server address | |
| 24 | 22 | int port = 8080; | |
| 25 | 23 | ||
| 26 | 24 | WiFiClient wifi; | |
| 27 | 25 | HttpClient client = HttpClient(wifi, serverAddress, port); | |
| 28 | 26 | int status = WL_IDLE_STATUS; | |
| 29 | - String response; | ||
| 30 | - int statusCode = 0; | ||
| 31 | 27 | ||
| 32 | 28 | void setup() { | |
| 33 | 29 | Serial.begin(9600); | |
@@ -57,8 +53,8 @@ void loop() { | |||
| 57 | 53 | client.post("/", contentType, postData); | |
| 58 | 54 | ||
| 59 | 55 | // read the status code and body of the response | |
| 60 | - statusCode = client.responseStatusCode(); | ||
| 61 | - response = client.responseBody(); | ||
| 56 | + int statusCode = client.responseStatusCode(); | ||
| 57 | + String response = client.responseBody(); | ||
| 62 | 58 | ||
| 63 | 59 | Serial.print("Status code: "); | |
| 64 | 60 | Serial.println(statusCode); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments