473,473 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

GET Request w/fsockopen()

Han
The following function retreives a GET request. It works great with many
sites (exp. www.msn.com), but others just hang (exp. www.ebay.com) or return
an error (exp. www.microsoft.com).

I've tried adding additional headers like "Referer" and "Accept", but it
doesn't make a difference.

What needs to be done to satisfy those web servers that won't cooperate?

Thanks.

----------------------------------------------------------------------------
-

$link = "http://www.domain.com?param1=string";

$http_response = "";
$url = parse_url($link);
$fp = fsockopen($url[host], 80, $err_num, $err_msg, 30) or die("Socket-open
failed--error: ".$err_num." ".$err_msg);
fputs($fp, "GET /$url[path]?$url[query] HTTP/1.0\n");
fputs($fp, "Connection: close\n\n");
while(!feof($fp)) {
$http_response .= fgets($fp, 128);
}
fclose($fp);
echo $http_response;
Jul 17 '05 #1
5 22908
Han
Ok, I think part of the problem is that my function is being called from
within a frame. The path and host references are wrong. I might have to
reconsider where the request originates...

"Han" <no****@nowhere.com> wrote in message
news:dy0fb.483273$cF.168086@rwcrnsc53...
The following function retreives a GET request. It works great with many
sites (exp. www.msn.com), but others just hang (exp. www.ebay.com) or return an error (exp. www.microsoft.com).

I've tried adding additional headers like "Referer" and "Accept", but it
doesn't make a difference.

What needs to be done to satisfy those web servers that won't cooperate?

Thanks.

-------------------------------------------------------------------------- -- -

$link = "http://www.domain.com?param1=string";

$http_response = "";
$url = parse_url($link);
$fp = fsockopen($url[host], 80, $err_num, $err_msg, 30) or die("Socket-open failed--error: ".$err_num." ".$err_msg);
fputs($fp, "GET /$url[path]?$url[query] HTTP/1.0\n");
fputs($fp, "Connection: close\n\n");
while(!feof($fp)) {
$http_response .= fgets($fp, 128);
}
fclose($fp);
echo $http_response;

Jul 17 '05 #2
Han
Ok, it seems the problem is related to the HTTP version. 1.0 works great,
but 1.1 complains about a missing host header. I added a host, but I still
get the same message.

"Han" <no****@nowhere.com> wrote in message
news:dt********************@rwcrnsc52.ops.asp.att. net...
Ok, I think part of the problem is that my function is being called from
within a frame. The path and host references are wrong. I might have to
reconsider where the request originates...

"Han" <no****@nowhere.com> wrote in message
news:dy0fb.483273$cF.168086@rwcrnsc53...
The following function retreives a GET request. It works great with many
sites (exp. www.msn.com), but others just hang (exp. www.ebay.com) or

return
an error (exp. www.microsoft.com).

I've tried adding additional headers like "Referer" and "Accept", but it
doesn't make a difference.

What needs to be done to satisfy those web servers that won't cooperate?

Thanks.


--------------------------------------------------------------------------
--
-

$link = "http://www.domain.com?param1=string";

$http_response = "";
$url = parse_url($link);
$fp = fsockopen($url[host], 80, $err_num, $err_msg, 30) or

die("Socket-open
failed--error: ".$err_num." ".$err_msg);
fputs($fp, "GET /$url[path]?$url[query] HTTP/1.0\n");
fputs($fp, "Connection: close\n\n");
while(!feof($fp)) {
$http_response .= fgets($fp, 128);
}
fclose($fp);
echo $http_response;


Jul 17 '05 #3
Han wrote on Thursday 02 October 2003 21:23:
Ok, it seems the problem is related to the HTTP version. 1.0 works great,
but 1.1 complains about a missing host header. I added a host, but I still
get the same message.


This is not a direct answer to your question, but if you would like to see a
working HTTPClient implementation, get my ActiveLink PHP XML Package from:

http://php-xml.sourceforge.net/

and take a look at HTTPClient and Socket classes. They are somewhat limited
in functionality right now (it's their 1st release) but a simple GET
request should work with both 1.0 and 1.1 version of the protocol.

Good luck!

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Jul 17 '05 #4
Han
Ok, fixed the problem.

Just in case this happens to someone else, here's the answer to my original
delimma.

Web servers are very particular about the number of line feeds and carriage
returns that follow headers. Some need "\r\n" and others "\r\n\r\n". Also,
you need to include a host header to make HTTP 1.1 servers happy. 1.0
servers don't require this and will ignore it.

"Han" <no****@nowhere.com> wrote in message
news:KQ6fb.672961$uu5.110283@sccrnsc04...
Ok, it seems the problem is related to the HTTP version. 1.0 works great,
but 1.1 complains about a missing host header. I added a host, but I still
get the same message.

"Han" <no****@nowhere.com> wrote in message
news:dt********************@rwcrnsc52.ops.asp.att. net...
Ok, I think part of the problem is that my function is being called from
within a frame. The path and host references are wrong. I might have to
reconsider where the request originates...

"Han" <no****@nowhere.com> wrote in message
news:dy0fb.483273$cF.168086@rwcrnsc53...
The following function retreives a GET request. It works great with many sites (exp. www.msn.com), but others just hang (exp. www.ebay.com) or

return
an error (exp. www.microsoft.com).

I've tried adding additional headers like "Referer" and "Accept", but it doesn't make a difference.

What needs to be done to satisfy those web servers that won't cooperate?
Thanks.


--------------------------------------------------------------------------
--
-

$link = "http://www.domain.com?param1=string";

$http_response = "";
$url = parse_url($link);
$fp = fsockopen($url[host], 80, $err_num, $err_msg, 30) or

die("Socket-open
failed--error: ".$err_num." ".$err_msg);
fputs($fp, "GET /$url[path]?$url[query] HTTP/1.0\n");
fputs($fp, "Connection: close\n\n");
while(!feof($fp)) {
$http_response .= fgets($fp, 128);
}
fclose($fp);
echo $http_response;




Jul 17 '05 #5
Han wrote:
Ok, fixed the problem.

Just in case this happens to someone else, here's the answer to my original
delimma.

Web servers are very particular about the number of line feeds and carriage
returns that follow headers. Some need "\r\n" and others "\r\n\r\n". Also,
you need to include a host header to make HTTP 1.1 servers happy. 1.0
servers don't require this and will ignore it.


Not to sound like a jerk, but you really should read the spec. All
lines must end with \r\n. Plus, the final line must end with another
\r\n. So, your request should be:
GET /?param1=string HTTP/1.1\r\n
Host: www.domain.com\r\n
Connection: close\r\n\r\n
Jul 17 '05 #6

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

Similar topics

3
by: Michael T. Peterson | last post by:
I am trying to get the file referenced by the following url: http://waterdata.usgs.gov/wa/nwis/uv?dd_cd=01&dd_cd=02&format=rdb&period=1&site_no=12149000 I'm using parse_url to get the host,...
9
by: fipaj1992 | last post by:
Hi! I have very big problem with fsockopen() function. It is very important... That's code: <?php $test = fsockopen ('chrome.pl', '8080'); ?>
1
by: Syl | last post by:
Hi group - I have a database table with 4 columns that hold a url. I am selecting each url and I need to check to see if it is valid. I assumed I could use the fsockopen command. I've had to...
2
by: Alex | last post by:
Hi all, I'm having a problem with fsockopen function, I'm programming with php 4.3 and need to do an HTTP POST over secure socket, ssl, here's my code: $context = stream_context_create();...
3
by: Aetherweb | last post by:
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...
5
by: xieliwei | last post by:
I have a freshly installed openSuSe 10.2 with PHP4 from http://download.opensuse.org/repositories/home:/michal-m:/php4/openSUSE_10.2/ (openSuSe abandoned PHP4 since version 10, but I have customers...
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,...
6
by: henryrhenryr | last post by:
Hi I'm really hoping for some ideas! I have been setting up phpmailer on my server and it was working nicely on my local server so I uploaded to my live server and tested. The mystery is that...
6
by: 703designs | last post by:
I'm writing a little Drupal module that implements a couple forms, relaying the submitted values to a third-party site. I know the target URL and I have all of the values that I want to submit with...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.