0

For some reason I can't seem to pass a simple string from one variable to another. Below is my code:

 HTTPClient http; // Declare an object of class HTTPClient
 http.begin(address); // Specify request destination
 int httpCode = http.GET(); // Send the request
 Serial.println("String: " + http.getString());
 String prp = http.getString();
 Serial.println("temp string: " + prp);

It prints out:

String: < ! DOCTYPE HTML> 26

temp string:

Why doesnt my string get correctly passed on to my temporary string variable?

Tom

asked May 16, 2018 at 14:05

1 Answer 1

3

The getString() method calls writeToStream which is documented write all message body / payload to Stream. It writes all the data of the http response to he output and doesn't store them internally. The next call has nothing to read because the first call to getString() put everything out.

answered May 16, 2018 at 14:31
4
  • Is there a way I can adapt my code so that it will still work? Commented May 16, 2018 at 18:49
  • isn't it obvious? read into variable and then print the value of the variable. remove the redundant println Commented May 16, 2018 at 19:00
  • Isn't that what I do? The first println works fine, it's the second one that's the problem! Commented May 16, 2018 at 19:04
  • you throw away the String used in first println. but the response was only in that String. call to getString put the received bytes into that String. Commented May 16, 2018 at 19:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.