0

The response to my http.Get() method which is in hex supposed to look like 0x00,0x00,0x00,0x00,0x04,0x08,0xff but when u try to collect the data using response = http.getString() ; i got empty string may be cause getString() terminate it by seeing 0x00 (NULL)

So is there any method to replace getString() or to receive unit8_t bytes in get method response

ps code work as it supose to if I edit the response to 0x04,0x08,0xff on server

6
  • 1
    http protocol is designed to communicate using entirely ascii visible code strings. If you do not want to communicate using 'text' then do not use the http protocol. Commented Jun 5, 2018 at 17:41
  • @webmite Images are sent via HTTP protocol and they are binary. Commented Jun 5, 2018 at 18:09
  • @gre_gor only when properly encapsulated within the protocol. The question specifically says that they are trying to use the getString() function. Hence a 'String' is the expected datatype. Commented Jun 5, 2018 at 18:16
  • Just to clarify I get my binary values if they are not starting with null Commented Jun 5, 2018 at 23:06
  • What normally marks the end of a string? Why wouldn't you expect a function named "getString" to end there? Commented Jun 6, 2018 at 4:45

1 Answer 1

0

Use http.getstream

WiFiClient * stream = http.getStreamPtr();
      while(http.connected() && (len > 0 || len == -1)) 
      {
      // get available data size
      size_t size = stream->available();
      if(size) {
       // read up to 128 byte
      int c = stream->readBytes(response, ((size > sizeof(response)) ? 
      sizeof(response) : size));
      if(len > 0) {
                  len -= c;
                  }
               }
       delay(1);

}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.