1
0
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:
Sandeep Mistry
2016-06-22 12:47:56 -04:00
parent bdc5281733
commit f56eecbc6f
10 changed files with 43 additions and 80 deletions

View File

@ -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);