大家好,我想从我的arduino程序发送一个http请求到我的本地nodejs服务器。
你能帮我一下吗?
我将使用此代码,但其状态代码是-1:
void gotoServer() {
String postData = "id=" + String(payload);
Serial.println("************");
Serial.println(postData);
HTTPClient http;
http.begin("http://192.168.1.83:3000/");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST(postData);
payload = http.getString();
Serial.print("Data: ");
Serial.println(postData);
Serial.print("httpCode: ");
Serial.println(httpCode);
Serial.print("payload : ");
Serial.println(payload);
}
```` `
would you examine this and help me?
我认为您可能需要将 WiFiClient 传递到此行中的 http.begin() :
http.begin("http://192.168.1.83:3000/");
试试这个
#include <WiFi.h>
WiFiClient client; //<<need this
void gotoServer() {
......
http.begin(client, "http://192.168.1.83:3000/"); //<< "client" to be included here
....
}