我有一个ESP8266,我正在编程在Arduino中。我需要做一个POST请求。我试过这段代码:ESP8266和POST请求
#include
#include
void setup() {
Serial.begin(115200); //Serial connection
WiFi.begin("ssid", "wifi_password"); //WiFi connection
while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI connection completion
delay(500);
Serial.println("Waiting for connection");
}
}
void loop() {
if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status
HTTPClient http; //Declare object of class HTTPClient
http.begin("server_name"); //Specify request destination
http.header("POST/HTTP/1.1");
http.header("Host: server_name");
http.header("Accept: */*");
http.header("Content-Type: application/x-www-form-urlencoded");
int httpCode = http.POST("Message from ESP8266"); //Send the request
String payload = http.getString();
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
}else{
Serial.println("Error in WiFi connection");
}
delay(5000); //Send a request every 30 seconds
}
但是在网页上我没有收到任何回应。
2016-12-28
Matej
+0
“但在网页上我没有收到任何回应” - 什么网页?为什么回复会在**网页上显示**? –
+0
'http.header(“Content-Type:application/x-www-form-urlencoded”); '和'http.POST(“来自ESP8266的消息”);' - 那些不匹配。 –
+0
在网页上是mysql数据库。什么是正确的? –