esp8266post请求html,ESP8266和POST请求

我有一个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数据库。什么是正确的? –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值