通过 ESP8266 的 Http 请求

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

我正在尝试向 nodeJs 服务器发送 API 调用,但未调用 API。

StaticJsonDocument<200> doc;
  doc["UID"] = tagID;
  String payload;
  serializeJson(doc, payload);
  Serial.print(payload);

  http.begin(wifiClient, serverUrl);
  http.addHeader("Content-Type", "application/json");
  int httpResponseCode = http.POST(payload);

  //  int httpResponseCode = http.POST("{\"UID\":\" 99 3C AB D5\"}");
  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);

  // Free resources
  http.end();

http.POST("{"UID":"99 3C AB D5"}");返回 -1 作为状态代码。 API 未被调用,因为服务器上的打印语句不起作用。

node.js api iot esp8266 nodemcu
© www.soinside.com 2019 - 2024. All rights reserved.