小编Mat*_*tej的帖子

ESP8266和POST请求

我有一个ESP8266,我正在Arduino中进行编程。我需要发出POST请求。我尝试了这段代码:

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

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); …
Run Code Online (Sandbox Code Playgroud)

post arduino request connect esp8266

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

arduino ×1

connect ×1

esp8266 ×1

post ×1

request ×1