我正在做一个项目,我有三天的问题。我正在用ESP32做这个项目,想要自动连接到WIFI并获取API信息。第一部分没关系,我没有任何问题。但它没有得到API信息。我的API-Link是这样的:
http://test.de/milad/api/Tv
它需要一个用户和密码:
User: Demo
Pass: OIMLyyIR03QZTqN2KFZkDKneuuk5ixMgeGOHS7r3
我试着阅读互联网上的所有BASIC-Auth示例。但我找不到解决方案......我收到此错误:
[HTTP] GET... failed, error: connection refused
例如,我使用了这段代码:
// wait for WiFi connection
if((wifiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
USE_SERIAL.print("[HTTP] begin...\n");
// configure traged server and url
http.begin("http://test.de/milad/api/Tv");
http.setAuthorization("demo", "OIMLyyIR03QZTqN2KFZkDKneuuk5ixMgeGOHS7r3");
USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
USE_SERIAL.println(payload);
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
服务器使用摘要式身份验证,而ESP32上的HTTPClient库目前仅支持基本身份验证。