Bro*_*mid 6 httpclient arduino-esp8266
我尝试用 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;
}
Run Code Online (Sandbox Code Playgroud)
错误:退出状态 1 调用使用属性声明的“HTTPClient::begin”错误:过时的 API,使用 ::begin(WiFiClient, url)
The*_*ese 14
您还需要从 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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46245 次 |
| 最近记录: |