完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,
我正在尝试连接 Nest_api ( ) 除了我遇到的棘手的安全问题外,我什至无法从 我尝试过的 API 中获取数据有几件事,我总是会收到“重定向”错误。这意味着我没有访问权限。 我开始相信我在 HTTPS 请求方面遇到了一些问题。有人遇到过类似的问题吗? 你可以在这里查看我的代码: 我尝试访问服务器的部分是最后一段代码。 代码:全选Basic Infos The goal is to let a switch respond on the data received from my nest Thermostad. I'm using the Nest_API to get the result Hardware Hardware: ESP8266 Description I'm trying to access the Nest API without any success. I always get some kind of redirection error. Or I get the 307 error code (redirection) or an 400. With the first one, there's no redirection location. What do i do wrong? Is it possible that the library doesn't support HTPPS? Is there a solution for it? Settings in IDE Module: Generic ESP8266 Module Sketch #include #include #include #include #define USE_SERIAL Serial String accessurl = "https://api.home.nest.com/oauth2/access_token"; MDNSResponder mdns; // My Network cred. const char* ssid = "Blanked out"; const char* password = "Blanked out"; int gpio13Led = 13; int gpio12Relay = 12; void setup(void){ // preparing GPIOs pinMode(gpio13Led, OUTPUT); digitalWrite(gpio13Led, HIGH); pinMode(gpio12Relay, OUTPUT); digitalWrite(gpio12Relay, HIGH); Serial.begin(115200); delay(5000); WiFi.begin(ssid, password); Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); if (mdns.begin("esp8266", WiFi.localIP())) { Serial.println("MDNS responder started"); } } void loop(void){ Serial.println("Wifi Up - Test Start!"); delay(10000); if((WiFi.status() != WL_CONNECTED)) { Serial.println("wifi down"); return; } HTTPClient http; //Here I gave the footprint along with the url. But I'm not sure if it works. http.begin("https://developer-api.nest.com/", "87:CB:F2:E6:44:C0:AA:F2:4C:28:B2:97:85:70:18:92:45:1B:A4:57"); //http.addHeader("Cache-Control", "no-cache", true, true); //http.addHeader("Postman-Token", "419da1fa-6070-3338-c215-8be740891136", true, true); http.addHeader("Authorization", "Bearer c.blanked out", true, true); http.addHeader("Host", "developer-api.nest.com", true, true); http.addHeader("Content-Type", "application/json", false, true); int httpCode = http.GET(); Serial.println("request sent: n"); Serial.println(httpCode); //Doesn't seem to work? I never see any outprint. if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); Serial.printf("[HTTP] GET response: %s", payload.c_str()); } else { String payload = http.getString(); String loc = http.header("Location"); Serial.printf("[HTTP] GE returned %d. kapot, error: %s; response: %s, new location: %sn", httpCode, http.errorToString(httpCode).c_str(), payload.c_str(), loc.c_str()); } http.end(); } |
|
相关推荐 |
|
只有小组成员才能发言,加入小组>>
545浏览 6评论
457浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
438浏览 5评论
441浏览 4评论
411浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 13:16 , Processed in 0.728956 second(s), Total 76, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号