Error: call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)

Error: call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)

我试着用 esp8266 做一个时钟新闻天气滚动字幕。但是当我上传代码时出现错误。你能帮助我吗? 这是代码的一部分:(根据 MIT 许可证(版权所有 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;  
    }

我看到了这个 post 并检查了这个,我在本周早些时候将 esp8266 核心更新到 v3.0.0 并且还发现 marquee scroller 无法编译并给出相同的错误,我已经重新安装了 v2 .7.4 并且是第一次编译。

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