22 Custom request header example for the ArduinoHttpClient
33 library. This example sends a GET and a POST request with a custom header every 5 seconds.
44
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-
115 based on SimpleGet example by Tom Igoe
126 header modifications by Todd Treece
7+ modified 22 Jan 2019
8+ by Tom Igoe
139
1410 this example is in the public domain
15- */
16-
11+ */
12+
1713#include < ArduinoHttpClient.h>
1814#include < WiFi101.h>
1915
@@ -29,8 +25,6 @@ int port = 8080;
2925WiFiClient wifi;
3026HttpClient client = HttpClient(wifi, serverAddress, port);
3127int status = WL_IDLE_STATUS;
32- String response;
33- int statusCode = 0 ;
3428
3529void setup () {
3630 Serial.begin (9600 );
@@ -53,16 +47,15 @@ void setup() {
5347}
5448
5549void loop () {
56-
5750 Serial.println (" making GET request" );
5851 client.beginRequest ();
5952 client.get (" /" );
6053 client.sendHeader (" X-CUSTOM-HEADER" , " custom_value" );
6154 client.endRequest ();
6255
6356 // 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 ();
6659
6760 Serial.print (" GET Status code: " );
6861 Serial.println (statusCode);
@@ -81,6 +74,8 @@ void loop() {
8174 client.sendHeader (" X-CUSTOM-HEADER" , " custom_value" );
8275 client.endRequest ();
8376 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);
8479
8580 // read the status code and body of the response
8681 statusCode = client.responseStatusCode ();
0 commit comments