You've already forked ArduinoHttpClient
mirror of
https://github.com/arduino-libraries/ArduinoHttpClient.git
synced 2025-06-11 17:08:08 +03:00
Add optional content type, content length and body parameters to post, put, and startRequest
Also, flush client RX data in start request, if state is ready body.
This commit is contained in:
@ -63,9 +63,7 @@ void loop() {
|
||||
|
||||
// send the GET request
|
||||
Serial.println("making GET request");
|
||||
client.beginRequest();
|
||||
client.get(path);
|
||||
client.endRequest();
|
||||
|
||||
// read the status code of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
|
@ -56,6 +56,8 @@ void loop() {
|
||||
String dweetName = "scandalous-cheese-hoarder";
|
||||
String path = "/dweet/for/" + dweetName;
|
||||
|
||||
String contentType = "application/json";
|
||||
|
||||
// assemble the body of the POST message:
|
||||
int sensorValue = analogRead(A0);
|
||||
String postData = "{\"sensorValue\":\"";
|
||||
@ -65,12 +67,7 @@ void loop() {
|
||||
Serial.println("making POST request");
|
||||
|
||||
// send the POST request
|
||||
client.beginRequest();
|
||||
client.post(path);
|
||||
client.sendHeader("Content-Type", "application/json");
|
||||
client.sendHeader("Content-Length", postData.length());
|
||||
client.endRequest();
|
||||
client.write((const byte*)postData.c_str(), postData.length());
|
||||
client.post(path, contentType, postData);
|
||||
|
||||
// read the status code and content length of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
|
@ -49,12 +49,9 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
Serial.println("making GET request");
|
||||
client.get("/");
|
||||
|
||||
// read the status code and content length of the response
|
||||
client.beginRequest();
|
||||
client.get("/");
|
||||
client.endRequest();
|
||||
|
||||
statusCode = client.responseStatusCode();
|
||||
contentLength = client.contentLength();
|
||||
|
||||
|
@ -50,14 +50,10 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
Serial.println("making POST request");
|
||||
String contentType = "application/x-www-form-urlencoded";
|
||||
String postData = "name=Alice&age=12";
|
||||
|
||||
client.beginRequest();
|
||||
client.post("/");
|
||||
client.sendHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
client.sendHeader("Content-Length", postData.length());
|
||||
client.endRequest();
|
||||
client.write((const byte*)postData.c_str(), postData.length());
|
||||
client.post("/", contentType, postData);
|
||||
|
||||
// read the status code and content length of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
|
@ -50,14 +50,10 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
Serial.println("making PUT request");
|
||||
String contentType = "application/x-www-form-urlencoded";
|
||||
String putData = "name=light&age=46";
|
||||
|
||||
client.beginRequest();
|
||||
client.put("/");
|
||||
client.sendHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
client.sendHeader("Content-Length", putData.length());
|
||||
client.endRequest();
|
||||
client.write((const byte*)putData.c_str(), putData.length());
|
||||
client.put("/", contentType, putData);
|
||||
|
||||
// read the status code and content length of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
|
Reference in New Issue
Block a user