Particle HTTP Client


#1

Hi All

I am trying to use HTTP client to recieve a JSON string from a stocks web API but can not get it to work. I have tried troubleshooting and looking at all of the existing http client advice on the forum, but still have not gotten it to work, and continually receive no data from the server.

Here is my code, help would be appreciated:

#include <HttpClient.h>


HttpClient http;
http_header_t headers[] = {
    { "Accept" , "*/*"},
    { "User-agent", "www.alphavantage.co HttpClient"},
    { NULL, NULL }
};



http_request_t request;
http_response_t response;


// Set up the gauge motors

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

    request.hostname = "www.alphavantage.co";
    request.port = 80;
    char conditionsRequestPath[100];
    sprintf(conditionsRequestPath, "/query?function=TIME_SERIES_INTRADAY&symbol=TCEHY&interval=5min&apikey=DOXC7CQZ904B63J2");
    request.path = conditionsRequestPath;
}


void loop()
{
    Serial.println("response: "+response.body);
    
}


#2

You are setting up a request but not actually issuing the request.

But if you did, you’d get a HTTP status 301 which means “Permanently moved” - most likely because it’s not HTTP but HTTPS


#3

Thank you for your response!

I just got the 301 error. How would I go about fixing this? I have tried looking for solutions but none of them have worked so far?


#4

HTTPClient does not support HTTPS.
This would typically be a case for a webhook
https://docs.particle.io/tutorials/device-cloud/webhooks/