你好,我正在尝试从 esp32 向节点 red 发出获取请求,我已经成功发出请求,但我只收到空的:
`
#include <SPI.h>
#include <HttpClient.h>
#include <Ethernet.h>
#include <EthernetClient.h>
// This example downloads the URL "http://arduino.cc/"
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
// unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
// Name of the server we want to connect to
const char kHostname[] = "3.145.1.222";
// Path to download (this is the bit after the hostname in the URL
// that you want to download
const char kPath[] = "/data";
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// Number of milliseconds to wait without receiving any data before we give up
const int kNetworkTimeout = 30 * 1000;
// Number of milliseconds to wait if no data is available before trying again
const int kNetworkDelay = 1000;
void setup()
{
// initialize serial communications at 9600 bps:
Serial.begin(9600);
Ethernet.init(5);
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(15000);
}
}
void loop()
{
Serial.println("Hello wo");
int err = 0;
EthernetClient client;
HttpClient http(client);
err = http.get(kHostname,
1880,
kPath,
NULL);
if (err == 0)
{
Serial.println("startedRequest ok");
}
String temperature = "44";
String requestBody = "{\"temperature\":\"" + temperature + "\"}";
int contentLength = requestBody.length();
char contentLenght[] = "21";
char c[] = "{\"temperature\":\"44\"}";
http.sendHeader("Content-Type", "application/json");
http.sendHeader("Content-Length", String(contentLength).c_str());
http.sendHeader("");
http.print(requestBody);
Serial.println(http.responseStatusCode());
delay(10000);
}
`
我尝试过使用多个库,这是唯一一个成功获取请求但不幸的是空的库