6

I want to send HTTP request like a simple request for "http://google.com/" and then print the HTTP response headers on screen. How can it be done? I want the base code so that I can use it to send more complex GET and POST requests.

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

This shows me an empty popup box.

Sonia Sharma
  • 137
  • 1
  • 2
  • 8

1 Answers1

0

You can't use XMLHttpRequest cross domain unless requested server explicitly allow it and google.com doesn't explicitly allow it. However you may disable the web security feature of your browser, and then your same code will start working.