473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sending a GET request and getting the response using fsockopen.

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 = "www.myhost.com";
$request = "/myurl.php?param1=1&param2=2&param3=3";

$fp = 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);

stream_set_timeout($fp, 2, 0);

$response = '';
while (!feof($fp))
{
$response .= fread($fp, 1024);
}

print $response . "<BR>\n";
fclose($fp);
}
What am I doing wrong?

Thank you!!

Jan 30 '07 #1
3 8458
On Tue, 30 Jan 2007 03:36:36 -0800, Aetherweb <je******@gmail.comwrote:
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 = "www.myhost.com";
$request = "/myurl.php?param1=1&param2=2&param3=3";

$fp = 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 = '';
while (!feof($fp))
{
$response .= fread($fp, 1024);
}

print $response . "<BR>\n";
fclose($fp);
}
What am I doing wrong?

Thank you!!
--
Curtis
Jan 30 '07 #2
Rik
Aetherweb <je******@gmail.comwrote:
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 = "www.myhost.com";
$request = "/myurl.php?param1=1&param2=2&param3=3";

$fp = fsockopen($host, 80, $errno, $errstr, 3.0);

if ($fp)
{
# Send the get request then, with timeout...
fwrite($fp, "GET / HTTP/1.0\r\n" .
"GET $request HTTP/1.0\r\n" .

--
Rik Wasmus
Jan 30 '07 #3
Sorted. Thank you.

On Jan 30, 11:50 am, Rik <luiheidsgoe...@hotmail.comwrote:
Aetherweb <jeffs...@gmail.comwrote:
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 = "www.myhost.com";
$request = "/myurl.php?param1=1&param2=2&param3=3";
$fp = fsockopen($host, 80, $errno, $errstr, 3.0);
if ($fp)
{
# Send the get request then, with timeout...
fwrite($fp, "GET / HTTP/1.0\r\n" ."GET $request HTTP/1.0\r\n" .

--
Rik Wasmus
Jan 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Davis | last post by:
Any ASP functions can get the HTTP request and response headers? Thanks! John
2
by: Reena | last post by:
Hi, Working on .NET 2003. Using C# as server code. I have created a class with following code... using System; using System.Data.OracleClient; using System.Web; using...
10
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of...
7
by: Shapiro | last post by:
I have a scenario where I log a resquest to a database table and update the request with a corresponding response including the response time. I am using an HttpModule to do this. My challenge...
1
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as...
2
by: Vladimir Ghetau | last post by:
Hi guys, This is a weird problem, and I'm not sure if I got it right. Just a practical example, that will describe my problem: I'm connecting to google.com host on port 80 using fsock open,...
2
by: haytham2008 | last post by:
hi every body i have this problem while i trying to send email using php i found a function <?php mail(); ?> but does not work with me since i use smtp server with user name and password
3
by: vtpvp82 | last post by:
I am having problem in getting response from remote server for that I have written following script response got correctly but the data on the page is not displayed it gives “–“ in place of grid...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.