You've already forked ArduinoHttpClient
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:
@ -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);
|
||||
|
Reference in New Issue
Block a user