Has anyone had any luck with a HTTP Post Library and a Particle Electron? I tried the ‘HttpClient’ library with no luck. A simple code snippet sending to pastebin via HTTP Post would be fab, if anyone has managed it.
…and yes I’m aware this can be done without HTTP Post with Webhooks
Hi @peekay123, thanks for the response. I’ve copied the original example, changed to HTTP Post, attempting to Post to a requestbin, with no luck. Serial debugging is on.
Here’s my code:
// This #include statement was automatically added by the Particle IDE.
#include "HttpClient.h"
#include "application.h"
/**
* Declaring the variables.
*/
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
{ "Content-Type", "application/json" },
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println();
Serial.println("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
request.hostname = "http://requestb.in";
request.port = 80;
request.path = "/abcdefg";
// The library also supports sending a body with your request:
request.body = "{\"key\":\"value\"}";
// 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);
delay(10000);
}
I can’t for the life of me work out what is wrong! Just to clarify, this is a ‘Particle Electron’. @nmattisson could you provide some feedback is it’s your library?
@peekay123 Turns out the REST Server I’m contacting only accepts HTTPS connections…after all of this! And as far as I’m aware, there isn’t an easy way of implementing HTTPS on a Particle…