【求助】8266无法访问获取API响应
本帖最后由 问题有点大 于 2021-8-9 06:33 编辑开发板是NodeMCU,用的库是blinker.h(只是用来联网的)。具体问题为开发板无法从https://api.miri.site/mcPlayer/get.php?ip=bm.lafamc.com&port=996这个网址获取响应(但是电脑浏览器访问这个网址能正常获取响应)。开发板能正常从B站获取响应。望大佬解惑:Q
代码如下
#define BLINKER_WIFI
#include <Blinker.h>
StaticJsonDocument<1024> doc;
char auth[] = "";
char ssid[] = "";
char pswd[] = "";
const String Url = "https://api.miri.site/mcPlayer/get.php?ip=bm.lafamc.com&port=996";//API
int online_max = 2019; //在线人数上限
int online = 0;//实际在线人数
Stringplayer_list;
char player_temp;
// 新建组件对象
BlinkerButton Button1("btn-abc");
BlinkerNumber Number1("num-abc");
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data) {
BLINKER_LOG("Blinker readString: ", data);
}
void setup() {
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
// 初始化有LED的IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachDataStorage(dataStorage);
Button1.attach(button1_callback);
}
void loop() {
Blinker.run();
getFollower(Url);
}
void dataStorage()
{
Blinker.dataStorage("players", online);
}
void getFollower(const String &url) { //获取信息
HTTPClient http;
client.setTimeout(10000);
http.begin(url);
int httpCode = http.GET();
Serial.printf(" GET... code: %d\n", httpCode);
if (httpCode > 0){
Serial.println("Get OK");
String resBuff = http.getString();
Serial.println(resBuff);
DeserializationError error = deserializeJson(doc, resBuff);
// if (error)
// {
// Serial.println(F("deserializeJson() failed: "));
// return;
// }
online_max = doc["max"];
Serial.print("max:");
Serial.println(online_max);
}
else{
Serial.println(" GET... failed");
}
http.end();
Blinker.delay(10000);
}
目前明白了我的代码是用于http的,https好像还要证书来访问
页:
[1]