I am using the following script to send a GET request to a site however, I keep getting the error, No response from the Server.
- I have run wireshark to see any traffic being generated as a result of running this script, but there is no traffic.
- I can connect to the site from the Browser and I can also retrieve the contents by using the file_get_contents function, however using sockets, I am unable to do it.
Here is the code which makes use of sockets to send the request to the site and it returns the error: “No response from the Server” if the connection was not successful.
<?php
error_reporting(0);
set_time_limit(0);
ini_set("default_socket_timeout", 5);
function http_send($host, $packet)
{
if (!($sock = fsockopen($host, 80)))
die( "\n[-] No response from {$host}:80\n");
fwrite($sock, $packet);
return stream_get_contents($sock);
}
$host="http://example.com";
$path="/";
$packet = "GET {$path} HTTP/1.0\r\n";
$packet .= "Host: {$host}\r\n";
$packet .= "Connection: close\r\n\r\n";
http_send($host, $packet);
?>
So, what is wrong in the code above that it is unable to send the GET request?
It appears ok to me, it will form the HTTP Request Headers for the GET request and store in the $packet variable.
$host is the destination site name.
Then it calls the function, http_send which will send the request.
Error Output: [-] No response from http://example.com:80
Look at the error being returned by
fsockopenby passing in parameters forerrnoanderrstr: