问题描述
this is what i do in postmaster to make the request
嗨,我正在尝试从 esp8266 发出 http post 请求。我想要做的是将两个密钥,即序列号和功率输出发送到 aws 服务器并获得响应。当我使用 postmaster 做同样的事情时,一切正常,但是当我使用我的 nodemcu 时,它以 httpcode:-1 响应。我正在使用的代码附在下面。任何帮助表示赞赏
#include <ESP8266HTTPClient.h>
#include
void setup() {
Serial.begin(115200); //串口连接 WiFi.begin("Jinhit_Entertainment","10813ad0908"); //无线连接
while (WiFi.status() != WL_CONNECTED) { //等待WiFI连接完成
delay(500);
Serial.println("Waiting for connection");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //检查WiFi连接状态
HTTPClient http; //Declare object of class HTTPClient
http.begin("https://uczj81sy9d.execute-api.us-east-1.amazonaws.com/prod/inverterdata"); //Specify request destination
http.addHeader("Content-Type","text/plain"); //Specify content-type header
int httpCode = http.POST("serialnumber: 4001,poweroutput: 4.1"); //Send the request
String payload = http.getString(); //Get the response payload
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
} 其他{
Serial.println("Error in WiFi connection");
}
延迟(30000); //每30秒发送一个请求
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)