Sending HTTP requests from Spark Core to API [HttpClient Help]

I am using HTTP client https://github.com/nmattisson/HttpClient/ to send request to my API. I am receiving the requests from Spark Core but not the data. I have tried get and post requests both are not working. Here is the complete code

    #include "HttpClient/HttpClient.h"
    
    /**
    * 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", "text/html" },
        //  { "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 = "spark.myapi.com";
        request.port = 80;
        request.path = "/api.php";
    
        // The library also supports sending a body with your request:
        //request.body = "response={\"deviceID\":\""+Spark.deviceID()+"\", \"statusCode\": 1}";
        request.body = "response=1";
    
        // Get request
        http.post(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;
    }

Any help will be greatly appreciated.

Thanks

Hi Moazam,

DId you find a solution to this?..I’m facing a similar problem.

Thanks,

Joel

Hi Joel,

Yes, I used Rest Client library: https://github.com/llad/spark-restclient

Best of luck!