1
0
mirror of https://github.com/arduino-libraries/ArduinoHttpClient.git synced 2025-06-11 17:08:08 +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

@ -27,7 +27,6 @@ WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
int statusCode = 0;
int contentLength = 0;
String response;
void setup() {
@ -69,16 +68,9 @@ void loop() {
// send the POST request
client.post(path, contentType, postData);
// 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);