Using libcurl in photon


#1

Hi everyone.

I want to use libcurl with my Photon in order to do some POST/GET and others requests.
I’ve been searching for a while over the internet, but I’m not able to find a good solution for my problem.
I found some source code for curlcpp, a curl lib in c++ but there is an include curl/curl.h and I can’t find this.

If any of you can help me, I’ll be really happy :smile:

Thanks in advance :wink:


#2

First try with the HTTP library in the web IDE. It’s a lot slimmer than using the full curl library!


#3

Hi @jvanier, thanks for your answer :smile:

I’m working on it since an hour but I’ve never done any http request before, so it’s not that easy for me, I may need some tips or advices.
I’m mostly doing POST requests

EDIT :

I’ve got some trouble with HttpClient.
response.status is -1 and response.body is empty after http.post. I think that this is about authentication, but I don’t know where I missed something.

Here’s my current code :

#include "application.h"
#include "HttpClient/HttpClient.h"

http_header_t headers[] = {
     { "Content-Type", "application/json" },
    //{ "Accept" , "*/*"},
    { "X-Parse-Application-Id", "<MY X PARSE APPLICATION ID"},
    {"X-Parse-REST-API-Key", "<MY X PARSE REST API KEY>"},
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};

HttpClient http;
http_request_t request;
http_response_t response;

void setup() {
    Serial.begin(9600);
    request.hostname = "https://api.parse.com";
    request.port = 80;
    request.path = "/1/classes/Flotty";
}

void loop() {
    Serial.println("Application>\tStart of Loop.");
    
    request.body = "{\"test\":\"TOTO\"}";
    Serial.print("Body: ");
    Serial.println(request.body);
    
    http.post(request, response, headers);
    
    Serial.print("response.status: ");
    Serial.println(response.status);
    Serial.print("response.body: ");
    Serial.println(response.body);
    
    delay(10000);
}

#4

Were you able to figure this out?
Do you need to have your application ID as part of your URL?