错误:调用'HTTPClient::begin'声明属性错误:过时的API,使用::begin(WiFiClient,url)



我试着用esp8266做一个时钟新闻天气滚动字幕。但当我上传代码时,它出现了一个错误。你能帮我吗?以下是代码的一部分:(根据麻省理工学院许可证(版权所有2018 David Payne((

void PiHoleClient::getPiHoleData(String server, int port) {
errorMessage = "";
String response = "";
String apiGetData = "http://" + server + ":" + String(port) + "/admin/api.php?summary";
Serial.println("Sending: " + apiGetData);
HTTPClient http;  //Object of class HTTPClient
http.begin(apiGetData);// get the result (**the error code**)
int httpCode = http.GET();
//Check the returning code
if (httpCode > 0) {
response = http.getString();
http.end();   //Close connection
if (httpCode != 200) {
// Bad Response Code
errorMessage = "Error response (" + String(httpCode) + "): " + response;
Serial.println(errorMessage);
return;  
}

错误:退出状态1对"HTTPClient::begin"的调用声明为属性错误:过时的API,使用::begin(WiFiClient,url(

您还需要从WiFiClient.h创建一个新的WiFiClient实例,并将其传递到开头:

#include <WiFiClient.h>
WiFiClient wifiClient;
void PiHoleClient::getPiHoleData(String server, int port) {
errorMessage = "";
String response = "";
String apiGetData = "http://" + server + ":" + String(port) + "/admin/api.php?summary";
Serial.println("Request: " + apiGetData);
HTTPClient http;  //Object of class HTTPClient
http.begin(wifiClient, apiGetData);// get the result (**the error code**)
int httpCode = http.GET();
//Check the returning code
if (httpCode > 0) {
response = http.getString();
http.end();   //Close connection
if (httpCode != 200) {
// Bad Response Code
errorMessage = "Error response (" + String(httpCode) + "): " + response;
Serial.println(errorMessage);
return;  
}

我看到了这篇文章,并对此进行了检查,我在本周早些时候将esp8266核心更新到了v3.0.0,还发现marquee scroller没有编译,并给出了相同的错误,我重新安装了v2.7.4,它是第一次编译的。

https://www.gitmemory.com/issue/Qrome/marquee-scroller/186/846463005

相关内容

最新更新