You've already forked ArduinoHttpClient
mirror of
https://github.com/arduino-libraries/ArduinoHttpClient.git
synced 2025-08-16 21:41:56 +03:00
Updated examples and readme.md
This commit is contained in:
@@ -2,18 +2,14 @@
|
||||
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();
|
||||
|
Reference in New Issue
Block a user