繁体   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