簡體   English   中英

我無法使用我的 ESP8266 和 HTTP 請求從 Web 服務器中提取 json,它返回 HTML 而不是 JSON

[英]I can't pull json from a web server using my ESP8266 and HTTP requests, it returns HTML instead of JSON

我正在嘗試從我的 Web 服務器中提取 json,但它在腳本標記內返回一條錯誤消息,而不僅僅是發送 json 內容。 我哪里做錯了?

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

// Include the Wi-Fi library

const char* ssid     = "SSID"; 
const char* password = "PASSWORD"; 

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println('\n');
  
  WiFi.begin(ssid, password);
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

  int i = 0;
  while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(1000);
    Serial.print(++i); Serial.print(' ');
  }

  Serial.println('\n');
  Serial.println("Connection established!");  
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {

   HTTPClient http;
    http.begin("http://smartrock.epizy.com/1");
    int httpCode = http.GET();

    if (httpCode > 0) {

      String payload = http.getString();
      Serial.println(payload);
    }

    http.end();
  }
  delay(20000);
}

我希望輸出原始 json,但我收到一條錯誤消息:

<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("e19a8092269b9c478a5440e54fd2ade5");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://smartrock.epizy.com/1?i=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>

如果您使用瀏覽器手動嘗試,您還會遇到響應說

本網站需要 Javascript 才能運行,請在您的瀏覽器中啟用 Javascript 或使用支持 Javascript 的瀏覽器

...,如果您在瀏覽器中禁用 javascript。

該網站顯然不符合您的預期。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM