1
0
mirror of https://github.com/arduino-libraries/ArduinoHttpClient.git synced 2025-07-05 04:01:10 +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

@ -25,7 +25,6 @@ HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
String response;
int statusCode = 0;
int contentLength = 0;
void setup() {
Serial.begin(9600);
@ -51,16 +50,9 @@ void loop() {
Serial.println("making GET request");
client.get("/");
// read the status code and content length of the response
// read the status code and body of the response
statusCode = client.responseStatusCode();
contentLength = client.contentLength();
// read the response body
response = "";
response.reserve(contentLength);
while (client.available()) {
response += (char)client.read();
}
response = client.responseBody();
Serial.print("Status code: ");
Serial.println(statusCode);