1
0
mirror of https://github.com/arduino-libraries/ArduinoHttpClient.git synced 2025-06-16 02:21:40 +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

@ -26,7 +26,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);
@ -55,16 +54,9 @@ void loop() {
client.put("/", contentType, putData);
// 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);