我想像发送简单请求一样发送HTTP请求,例如 "http://google.com/" 并在屏幕上打印HTTP响应头。如何实现呢? 我需要基础代码,以便我可以使用它来发送更复杂的GET和POST请求。
<html>
<body>
<script type="text/javascript">
function sendgetreq()
{
var req = new XMLHttpRequest();
req.open('GET', "https://www.google.com/search?q=asd", true);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
//document.write("Headers are:"+headers);
alert(headers);
}
</script>
<INPUT TYPE=BUTTON OnClick="sendgetreq();" VALUE="Send Request">
</body>
</html>
这显示了一个空的弹出框。