[英]Why can't ESP8266 HTTP client receive data?
当我在浏览器中输入serverName时,它返回 json object。但在这里,它Serial.print(payload)返回 -1。 我怎样才能解决这个问题?
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
http.begin(serverName); //Specify request destination
int httpCode = http.GET();
//Send the request
if (httpCode > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
Serial.println(payload); //Print the response payload
}
http.end(); //Close connection
}
delay(10000); //Send a request every 30 seconds
}
使用 HTTP 而不是 HTTPS。
如果要使用 HTTPS,则必须指定服务器证书的 SHA1 指纹。 如何做到这一点很容易用谷歌搜索。
一些库将允许像client->setInsecure();
这样的东西。 ,但我不会在那里使用 go,因为它不安全。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.