HttpClient library - problem [SOLVED]

I’m running the sample code of HttpClient library, but I’m in trouble.
The request is not made, always returns status -1, and the spark restarts after a few tries.
It seems that the core is in loop, I need to do a hard reset to be able to send a new code.

Interestingly, it worked before, this problem started recently.

Code below:

/**
* Declaring the variables.
*/

unsigned int nextTime = 0;    // Next time to contact the server
HttpClient http;

// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
    //  { "Content-Type", "application/json" },
    //  { "Accept" , "application/json" },
    { "Accept" , "*/*"},
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};

http_request_t request;
http_response_t response;

void setup() {
    Serial.begin(9600);
}

void loop() {
    if (nextTime > millis()) {
        return;
    }

    Serial.println();
    Serial.println("Application>\tStart of Loop.");
    // Request path and body can be set at runtime or at setup.
    request.hostname = "www.innovasites.com.br";
    request.port = 80;
    request.path = "/spark/index.php?acao=verifica-digital&idFingerPrint=10";

    // The library also supports sending a body with your request:
    //request.body = "{\"key\":\"value\"}";

    // Get request
    http.get(request, response, headers);
    Serial.print("Application>\tResponse status: ");
    Serial.println(response.status);

    Serial.print("Application>\tHTTP Response Body: ");
    Serial.println(response.body);

    nextTime = millis() + 10000;
}

I have a sneaky feeling you might have trouble resolving DNS… have a read of this post and let us know what it comes up with.

2 Likes

@Hootie81 You’re right!
Thank you!