首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误:调用'HTTPClient::begin‘时声明了属性Error: obsolete API,请使用::begin(WiFiClient,url)

错误:调用'HTTPClient::begin‘时声明了属性Error: obsolete API,请使用::begin(WiFiClient,url)
EN

Stack Overflow用户
提问于 2021-05-26 18:09:26
回答 2查看 12.4K关注 0票数 2

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

代码语言:javascript
运行
复制
  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“”,使用属性error: obsolete API声明,请使用::begin(WiFiClient,url)“”

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-05-26 18:14:25

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

代码语言:javascript
运行
复制
#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;  
    }
票数 6
EN

Stack Overflow用户

发布于 2021-07-17 23:00:17

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67702822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档