amazon-web-services - 使用esp32到aws时如何解决错误400?
问题描述
新来的。
我正在做一个项目,我试图通过 HTTPS 帖子将一些数据发布到 AWS,但似乎无法正常工作,因为我收到了 400 条消息作为响应。我已经尝试过 Postman 并且我的 API 工作正常。
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "";
const char* password = "";
//Domain name with URL path or IP address with path
const char* serverName = ""
unsigned long lastTime = 0;
unsigned long timerDelay = 5000;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
}
void loop() {
//Send an HTTP POST request every 10 minutes
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if (WiFi.status() == WL_CONNECTED) {
WiFiClient client;
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(client, serverName);
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.POST("{\"INPUT\": \"hello world\"}");
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
关于什么可能是解决方案的任何syggestions?
解决方案
对于内容类型,您需要添加“\r\n”字符:
"Content-Type: application/json\r\n"
如果需要,您可能还需要传递证书信息。有关更多详细信息,请参阅这篇文章:
推荐阅读
- python - ValueError:ndarray 的最大支持维度为 32,找到 413
- powerbi - PowerBI:如何将 TupleFilter 与 powerbi-client 一起使用?
- python - 使用 arcpy 将 listlayers 转换为列表。(arcpro python3)
- sql - SQL:在一列中插入多个不同的硬编码值
- python - 在python中结合if和with?
- javascript - React Redux 不会重置某些组件的存储
- php - Laravel 多态关系与类型的附加表
- c# - 用 Visual Basic.NET (VB.NET) 开发的 ASP.NET Core 应用程序,有可能吗?VS 中没有模板
- unison - Unison 因“格式错误的消息”错误而失败,远程和本地版本相同
- r - 如何在 R 中使用备忘录