You are here: Re: Sending a GET request and getting the response using fsockopen. « PHP Programming Language « IT news, forums, messages
Re: Sending a GET request and getting the response using fsockopen.

Posted by Curtis on 01/30/07 11:43

On Tue, 30 Jan 2007 03:36:36 -0800, Aetherweb <jeffsnox@gmail.com> wrote=
:

> Hi,
>
> I need to use fsockopen to open a connection, send a GET request and
> read in the response. At the moment I'm trying the following code, but=

> I think it's ignoring the actual URL included in the $request
> variable.
>
> $host =3D "www.myhost.com";
> $request =3D "/myurl.php?param1=3D1&param2=3D2&param3=3D3";
>
> $fp =3D fsockopen($host, 80, $errno, $errstr, 3.0);
>
> if ($fp)
> {
> # Send the get request then, with timeout...
> fwrite($fp, "GET / HTTP/1.0\r\n" .
> "Host: $host\r\n".
> "Connection: close\r\n".
> "Content-Length: " . strlen($request) . "\r\n" .
> "\r\n" .
> $request);

The first line of the GET request needs to include the query string, as =
=

far as I know. Instead of using "GET / HTTP/1.0\r\n", try inserting =

$request in place of / after GET.

>
> stream_set_timeout($fp, 2, 0);
>
> $response =3D '';
> while (!feof($fp))
> {
> $response .=3D fread($fp, 1024);
> }
>
> print $response . "<BR>\n";
> fclose($fp);
> }
>
>
> What am I doing wrong?
>
> Thank you!!
>

-- =

Curtis

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация