#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "Popogway";
const char* password = "12346789";
const char cert_DigiCert_Global_Root_CA [] PROGMEM = R"CERT(
-----BEGIN CERTIFICATE-----
MIIGQzCCBSugAwIBAgIMSkhE2WLs9uHaOkEXMA0GCSqGSIb3DQEBCwUAMFMxCzAJ
BgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMSkwJwYDVQQDEyBH
bG9iYWxTaWduIEdDQyBSMyBEViBUTFMgQ0EgMjAyMDAeFw0yMzA4MDEwOTM4NTVa
Fw0yNDA5MDEwOTM4NTRaMBYxFDASBgNVBAMMCyouZGFkYXRhLnJ1MIIBIjANBgkq
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9Ybmeyr7BRP20aRsVz8xJ/YUGLGDDqWQ
ABhTsHQCGNyApRUCG7FDZYQXedhualCMqPPEDEtl4TVxid6n7LdsDnuqLQIvcdv6
QY4aZ2VIcHVFZGll2AbAPzdiBkhtssgx/gWw37Z64lRf0hHjDiXOEmP3M0lrO+0C
APYdFqeu95KyXmKsdPGRAUW9lnOdKwR/3gd4MksLj9cZmffN8l2rjY7vCBPOuCE6
zKthkqxzO7/D8BtQAy7X+dK6OR/8FlDKgdKUnk9aMfUmbCWJozT7KfeWNnctOsbu
QlSbkLISdnWZ6z6nAq6H6ZBBtg8EWBDTZk1Ys91lSqTU79OEiVVNJwIDAQABo4ID
UjCCA04wDgYDVR0PAQH/BAQDAgWgMIGTBggrBgEFBQcBAQSBhjCBgzBGBggrBgEF
BQcwAoY6aHR0cDovL3NlY3VyZS5nbG9iYWxzaWduLmNvbS9jYWNlcnQvZ3NnY2Ny
M2R2dGxzY2EyMDIwLmNydDA5BggrBgEFBQcwAYYtaHR0cDovL29jc3AuZ2xvYmFs
c2lnbi5jb20vZ3NnY2NyM2R2dGxzY2EyMDIwMFYGA1UdIARPME0wQQYJKwYBBAGg
MgEKMDQwMgYIKwYBBQUHAgEWJmh0d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XxyvfrCxBHCoOXpYswWaPd
Bjc7So3v3r4qZ4SzH2MjxvwgjwpfTC8c8BZosrkdDscn0jDUO/28IV8viffvGWy1
/5T6CMQMUOESKJraGc42HP+TQ0IOEpYbtA+JQO4X+jSRnEWrMghmRK/ZyWFArC79
9COMl54BB7r9iSPscTiWQnrbvQmhuJc=
-----END CERTIFICATE-----
)CERT";
const char* api_host = "cleaner.dadata.ru";
const uint16_t api_port = 443;
X509List cert(cert_DigiCert_Global_Root_CA);
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Set time via NTP, as required for x.509 validation
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
Serial.print("Waiting for NTP time sync: ");
time_t now = time(nullptr);
while (now < 8 * 3600 * 2) {
delay(500);
Serial.print(".");
now = time(nullptr);
}
Serial.println("");
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
Serial.print("Current time: ");
Serial.print(asctime(&timeinfo));
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
Serial.print("Connecting to ");
Serial.println(api_host);
Serial.printf("Using certificate: %s\n", cert_DigiCert_Global_Root_CA);
client.setTrustAnchors(&cert);
if (!client.connect(api_host, api_port)) {
Serial.println("Connection failed");
return;
}
String url = "/api/v1/clean/address";
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + api_host + "\r\n" +
"Content-Type: application/json" + "\r\n" +
"Accept: application/json" + "\r\n" +
"Authorization: Token ТОКЕН" + "\r\n" +
"X-Secret: КЛЮЧ" + "\r\n" +
"Connection: close\r\n\r\n");
Serial.println("Request sent");
while (client.available()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("Headers received");
break;
}
}
String line = client.readStringUntil('\n');
Serial.println(line);
line = client.readStringUntil('\n');
Serial.println(line);
}
void loop() {}
Как я понял, заголовки отправляются в методе client.print(), но спустя несколько часов поисков в интернете я так и не смог найти, как отправить данные. Мне нужно отправить ["Красноярск"]. Подскажите, пожалуйста, с помощью чего это можно сделать?