【发布时间】:2023-03-24 00:35:01
【问题描述】:
我正在使用 ESP8266 wifi 模块进行物联网项目。我已经能够使用 adafruit 提供的本教程成功地将其连接到 Internet 并向 html 页面发出 GET 请求。 但我似乎很难将它与我在谷歌开发者控制台上运行的 api 端点集成。
这是我遇到问题的代码药水
const char* Host = "www.my_app_id.appspot.com";
String PostData = "clientId=&fanId=&kueliiKey=";
String url = "/_ah/api/fan/v1/register?";
Serial.print("Requesting URL: ");
Serial.println(url);
//Connect to the client and make the api call
if (client.connect(Host, httpPort)) {
client.println("POST " + url + " HTTP/1.1");
client.println("Host: "+ (String)Host);
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(PostData.length());
client.println();
client.println(PostData);
delay(500);
}
//Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
//Serial.println();
Serial.println("closing connection");
我可以连接,但我不断收到 404 错误
lloc\umm_malloc.c
HTTP/1.1 404 Not Found
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Tue, 22 Mar 2016 12:08:06 GMT
Vary: X-Origin
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Accept-Ranges: none
Vary: Origin,Accept-Encoding
Connection: close
Not Found
closing connection;
我有什么
String url = "/_ah/api/fan/v1/register?";
可能是错误的,但我已经仔细检查并使用了 http://hurl.it 并且 api 调用有效并返回了我想要的 image of successful request 任何对此的见解将不胜感激。
谢谢。
【问题讨论】:
标签: arduino http-headers google-cloud-endpoints iot