Javascript ESP8266未收到HTTPRequest
我似乎无法接收Javascript的HTTPRequest。我得到这个Javascript ESP8266未收到HTTPRequest,javascript,arduino,esp8266,Javascript,Arduino,Esp8266,我似乎无法接收Javascript的HTTPRequest。我得到这个HTTP/1.1200ok 但我似乎无法获取发送过来的URL。我只想在我的网页上发送的链接 以下是我的javascript: jQuery(function($) {$("button").click(function(){ console.log(this.id); document.getElementById("direction").innerHTML = this.id + " is pressed.
HTTP/1.1200ok
但我似乎无法获取发送过来的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:
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消息以获得响应,特别是body-AssociationIndex.php使用body返回所需的数据。您可以在此处找到HTTP消息结构的描述: