Arduino ESP8266 發送HTTP請求 獲取蘇寧服務器時間


參考:發送HTTP請求

參考:獲取時間

#include <ESP8266WiFi.h>

#include <ESP8266HTTPClient.h>


//在這里輸入你家的WiFi名字和密碼
const char* ssid     = "hg2020"; 

const char* password = "12345678";   

HTTPClient http;

String GetUrl;

String response;

void setup() {

  // 連接到你家的WiFi

  delay(3000);

  Serial.begin(115200);

  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(".");

  }


  Serial.println("");

  Serial.println("WiFi connected");

  Serial.println("IP address: ");

  Serial.println(WiFi.localIP());


  // 連接蘇寧網站的授時網頁

  GetUrl = "http://quan.suning.com/getSysTime.do";

  http.setTimeout(5000);

  http.begin(GetUrl);


}


void loop() {

  // 從網站獲得網頁內容

  int httpCode = http.GET();

  if (httpCode > 0) {

      Serial.printf("[HTTP] GET... code: %d\n", httpCode);

      if (httpCode == HTTP_CODE_OK) {

        //讀取響應內容

        response = http.getString();
 
        Serial.println(response);

      }

  } else {

      Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());

  }

  http.end();

  delay(3000);

}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM