如何将http请求发送到我的电脑上的本地服务器 - localhost nodejs arduino esp32

问题描述 投票:0回答:1

大家好,我想从我的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?
node.js http arduino localhost httprequest
1个回答
0
投票

我认为您可能需要将 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

      ....

}
© www.soinside.com 2019 - 2024. All rights reserved.