diff --git a/HTTPClient.cpp b/HTTPClient.cpp old mode 100644 new mode 100755 index dea3547..d21f4fd --- a/HTTPClient.cpp +++ b/HTTPClient.cpp @@ -203,6 +203,10 @@ char HTTPClient::sendUriAndHeaders(FILE* stream, char* hostName, const char* requestType, char* uri, http_client_parameter parameters[], http_client_parameter headers[]) { + if (stream == NULL) + { + return 0; + } fprintf_P(stream, requestType, uri); fprintf_P(stream, PSTR(" "), uri); //encode but use reserved characters @@ -256,6 +260,10 @@ HTTPClient::sendUriAndHeaders(FILE* stream, char* hostName, const char* requestT char HTTPClient::sendContentPayload(FILE* stream, char* data) { + if (stream == NULL) + { + return 0; + } //calculate the content length int content_length = 0; if (data != NULL) @@ -400,7 +408,22 @@ int HTTPClient::skipHeader(FILE* stream) { //skip over the header - fscanf_P(stream, PSTR("HTTP/1.1 %i"), &lastReturnCode); + int httpReturnCode; + lastReturnCode = NULL; + + if (stream == NULL) return NULL; + http_stream_udata* udata = (http_stream_udata*) fdev_get_udata(stream); + HTTPClient* client = udata->client; + + int delayReadHeaderCount=0; + // check if at least the first HTTP-response available, up to 1000ms=1s + while ((client->available()<17) && (delayReadHeaderCount++client->connected()) - { - udata->client->stop(); - } + udata->client->stop(); free(udata); fclose(stream); } diff --git a/HTTPClient.h b/HTTPClient.h old mode 100644 new mode 100755 index 63bbe7c..31417b1 --- a/HTTPClient.h +++ b/HTTPClient.h @@ -26,7 +26,14 @@ #define HTTPCLIENT_H_ #include -#include "EthernetClient.h" +#include + +/* With this we try a delay of 20 ms before checking again if content is available + * and we try this up to 50 times. + * So max: 20x50ms=1000ms=1s + */ +#define HTTPCLIENT_HEADER_READ_DELAY_ONCE 20 +#define HTTPCLIENT_HEADER_READ_DELAY_MAXCOUNT 50 /* This struct is used to pass parameters as URI paramters and additional HTTP headers. * normally you pass this as a array. The last entry must have the NULL-Pointer as name.