| re: problem with fsockopen and HTTP GET
Hi all,
I need some help, I am trying to access a service that binds to the
loopback address on my linux FC8 server. I think PHP functions but I
am unable to get any response back from the fgets() command below.
The service is GoogleDesktop for Linux, I am aware of all of the
restrictions in place to prevent what I am trying to do but I want to
try anyway. It seems to me that my http request should look just like
an http request from Firefox to the Google Desktop Search, so I
thought that I could mimic that request by using fsockopen and fgets.
I captured all of the headers in a request using Live Headers plugin
in Firefox, when I replay the headers with a GET request in Firefox it
works fine.
So my question is "what is wrong with my code below?" I should get an
error message back at least right? fgets returns nothing.
I even tried to do it with another website instead of 127.0.0.1, just
like cnn.com, again fgets returns nothing not even an error.
<?php
$fp = fsockopen("127.0.0.1", 31846 , $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET /?hl=en_US&src=14&s=4xrcacQv6jHUIsB0GtlFZ2j9QJw HTTP/1.1\r
\n";
$out .= "Host: 127.0.0.1:31846\r\n";
$out .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:
1.8.1.3) Gecko/20070320 Firefox/2.0.0.3\r\n";
$out .= "Accept: text/xml,application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
$out .= "Accept-Language: en-us,en;q=0.5\r\n";
$out .= "Accept-Encoding: gzip,deflate\r\n";
$out .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
$out .= "Keep-Alive: 300\r\n";
$out .= "Connection: keep-alive\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 4096);
}
fclose($fp);
}
?> |