我正在尝试使用esp8266设备连接到Google Firebase Firestore。我想发布请求,但无法连接到主机:
const char *host = "firestore.googleapis.com";
int r=0; //retry counter
while((!httpsClient.connect(host, httpsPort)) && (r < 30)){
delay(50);
Serial.print(".");
r++;
}
httpsClient.print(String("POST ") + "/v1beta1/projects/myproject/databases/(default)/documents/loggings" + " HTTP/1.1\r\n" +
"Host: " + "firestore.googleapis.com" + "\r\n" +
"Content-Type: application/json"+ "\r\n" +
"Content-Length: 240" + "\r\n\r\n" +
postData+ "\r\n" +
"Connection: close\r\n\r\n");
connect()函数不起作用,因为找不到主机(404)。我该如何使用connect函数获得与Firestore主机的正确连接?
答案 0 :(得分:0)
在connect()之前调用httpsClient.setInsecure()。然后跳过密钥验证。这不是安全的,但对于您的用例来说可能没问题。 httpsPort应该为443。对于我来说,连接fcm.googleapis.com的工作方式如下:
WiFiClientSecure client;
client.setInsecure(); // INSECURE!
client.connect("fcm.googleapis.com", 443);