簡體   English   中英

ESP8266未收到HTTPRequest

[英]ESP8266 not receiving HTTPRequest

我似乎無法收到Javascript的HTTPRequest。 我得到了HTTP/1.1 200 OK同意,但似乎無法獲得發送過來的URL。 我只想要我的網頁上發送的鏈接。

這是我的JavaScript:

jQuery(function($) {$("button").click(function(){
    console.log(this.id);
    document.getElementById("direction").innerHTML = this.id + " is pressed.";

    newurl = 'index.php?btn='+ this.id+"?key="+user.key; 
    sendHttpRequest(newurl);
    });
});

function sendHttpRequest(update){
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
          console.log(xhttp.responseText);
        }
    }
    xhttp.open("GET",update,true);
    xhttp.send(null);

    console.log(update);
}

ESP8266在void循環中:

WiFiClient client;
String url = "/index.php?";

client.print(String("GET ") + url + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" + 
             "Connection: close\r\n\r\n");
  Serial.println("Request Sent");


  String request = client.readStringUntil('\r');
  Serial.println("headers received");
  Serial.println(request);

您僅從ESP上的index.php腳本中讀取響應的第一行,通常是您所看到的HTTP狀態代碼,而沒有別的(除非您沒有發布其他代碼)。 您需要閱讀整個HTTP消息以獲取響應,特別是正文-假設index.php使用正文返回所需的數據。 您可以在此處找到HTTP消息結構的描述: https : //www.w3.org/Protocols/rfc2616/rfc2616-sec4.html

暫無
暫無

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

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