You've already forked ArduinoHttpClient
mirror of
https://github.com/arduino-libraries/ArduinoHttpClient.git
synced 2025-06-13 04:21:30 +03:00
Add new responseBody API to simplify reading response body as a String
This commit is contained in:
@ -33,7 +33,6 @@ WiFiClient wifi;
|
||||
HttpClient client = HttpClient(wifi, serverAddress, port);
|
||||
int status = WL_IDLE_STATUS;
|
||||
int statusCode = 0;
|
||||
int contentLength = 0;
|
||||
String response;
|
||||
|
||||
void setup() {
|
||||
@ -65,23 +64,11 @@ void loop() {
|
||||
Serial.println("making GET request");
|
||||
client.get(path);
|
||||
|
||||
// read the status code of the response
|
||||
// read the status code and body of the response
|
||||
statusCode = client.responseStatusCode();
|
||||
response = client.responseBody();
|
||||
Serial.print("Status code: ");
|
||||
Serial.println(statusCode);
|
||||
|
||||
// read the content length of the response
|
||||
contentLength = client.contentLength();
|
||||
Serial.print("Content Length: ");
|
||||
Serial.println(contentLength);
|
||||
|
||||
// read the response body
|
||||
response = "";
|
||||
response.reserve(contentLength);
|
||||
while (client.available()) {
|
||||
response += (char)client.read();
|
||||
}
|
||||
|
||||
Serial.print("Response: ");
|
||||
Serial.println(response);
|
||||
|
||||
|
Reference in New Issue
Block a user