[英]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.