boblemaire / asyncHTTPrequest

asynchronous HTTP for ESP using ESPasyncTCP. Works like XMLHTTPrequest in JS.
GNU General Public License v3.0
65 stars 31 forks source link

How to use onData() ? #8

Closed ersivv closed 5 years ago

ersivv commented 5 years ago

Hi. How to use onData() callback function?

boblemaire commented 5 years ago

Take a look at the sample that I posted in response to issue #9. In that sample you could just as well use onData() instead of onReadyStateChange. Doing so would look like:

void requestCB(void* optParm, asyncHTTPrequest* request, int len){
        Serial.println(request->responseText());
        Serial.println();
        request->setDebug(false);
}

So you would not be looking for readyState == 4; The difference is that if it were a long or chunked response, there would be multiple calls to onData. The result in this case should be the same.