-2

I`m trying to do POST request to my ssl server, using https. Here is my arduino code example:

#include "recipes/WiFi.h"
#include "Fetch.h"

#define SSID "My_wifi_name"
#define PASSPHRASE "My_wifi_pass"
#define FINGERPRINT "Sha-1 ssl cert from website"


void setup() {
    Serial.begin(9600);
    connectWiFi(SSID, PASSPHRASE);
}

void loop() {
    RequestOptions options;
    options.method = "POST";
    options.body = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\[48.756080,2.302038]}";
    options.fingerprint = FINGERPRINT;

    Response response = fetch("https://MYSITE.COM/post", options);

    // Printing res ponse.
    Serial.println(response);
    // Printing respons headers.
    Serial.printf("Connection Header: \"%s\"\n", response.headers["Content-Type"].c_str());
    Serial.printf("Connection Header: \"%s\"\n", response.headers["Connection"].c_str());
    delay(4500);
}

The problem, is that:

enter image description here

Python request with default data {"323": "323"} on server is ok, but my backend founds nothing in arduino request data.

Any ideas, how to fix it? Ty. Custom library GIThub: https://github.com/instanceofMA/arduino-fetch

2

1 Answer 1

0

Okay. You need to use at least:

options.headers["Content-Length"] = "LenghtOfYourJson";
options.headers["Content-Type"] = "application/json";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.