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; 5 22908
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;
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;
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/
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;
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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,...
|
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');
?>
|
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...
|
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();...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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: 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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |