github - 如何使用 ESP8266 上的令牌向 GitHub 进行身份验证?
问题描述
我可以从公共存储库更新,现在我想使用令牌向 GitHub 进行身份验证,以下载私有存储库的固件,但我收到连接被拒绝(错误代码 -1)。
我已经配置了证书和 NTP 时间,我不会放这个代码,因为它可以工作。但这里是我用作 base 的代码。
这是我的代码
BearSSL::WiFiClientSecure client;
bool mfln = client.probeMaxFragmentLength("https://api.github.com", 443, 1024); // server must be the same as in ESPhttpUpdate.update()
Serial.printf("MFLN supported: %s\n", mfln ? "yes" : "no");
if (mfln) {
client.setBufferSizes(1024, 1024);
}
client.setCertStore(&certStore);
HTTPClient http;
http.begin("https://api.github.com/repos/user/reponame/contents/firmware.bin");
http.addHeader("Accept", "application/vnd.github.v3+json");
http.addHeader("authorization", "Bearer token");
//http.setAuthorization("token");
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
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
return;
}
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, "https://api.github.com/repos/user/reponame/contents/firmware.bin");
我从来没有达到更新功能,因为我无法验证。
解决方案
看看你的代码。您正在设置,client
但您从不使用它。您需要将它传递给http.begin()
这样的:
http.begin(client, "https://github.com/user/reponame");
否则 HTTP 不知道要使用BearSSL::WiFiClientSecure
您费尽心思设置的那个。
推荐阅读
- r - ShinyDashboard 动态要点
- html - 如何使用嵌入标签显示pdf的第一页?
- tensorflow - 张量流调试
- javascript - JS 对象解构所需的库代码行?
- machine-learning - AutoEncoder 无法理解为什么我的解码图像看起来像热图?
- node.js - Google Async 问题上的操作:错误:未设置响应
- java - 如何将 Java 类添加到 Xamarin VS2017 项目
- spyder - 是否有需要使用 conda 安装 Pyomo、pyomo-extras 和 spyder 的顺序?
- python - 添加都在元组的索引 1 处的值
- kotlin - 如何在 kotlin 的 when 分支中使用空安全运算符?