473,856 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
+ 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 22927
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.4832 73$cF.168086@rw crnsc53...
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******** ************@rw crnsc52.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.4832 73$cF.168086@rw crnsc53...
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.6729 61$uu5.110283@s ccrnsc04...
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******** ************@rw crnsc52.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.4832 73$cF.168086@rw crnsc53...
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
4731
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, path, and query. My call to fsockopen() works correctly. Unfortunately, I can find no documentation for how to construct a request that will correctly instruct the server (i.e., waterdata.usgs.gov) to send me the file and all the combinations of...
9
18704
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
5182
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 parse the url, since it cannot take the http:// Here is my testing code : $query = 'select id, reg, lurl, lurl_f, burl, burl_f from srl where id = 862 order by id';
2
4869
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(); $result = stream_context_set_option($context, 'ssl', 'local_cert', "/certificate/cert.pem"); $result = stream_context_set_option($context, 'ssl', 'passphrase', "passphrase");
3
8512
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 the $request variable. $host = "www.myhost.com"; $request = "/myurl.php?param1=1&param2=2&param3=3";
5
3286
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 who need php4 support) The version strings are as follows: # uname -a Linux server2 2.6.18.2-34-default #1 SMP Mon Nov 27 11:46:27 UTC 2006 i686 athlon i386 GNU/Linux
2
4393
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, and I send a regular GET header without any specific HTTP headers regarding the type of encoding accepted, cookies, accepted charset, conditional headers etc
6
6003
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 it times out. The timeout occurs with fsockopen(). I have checked the php configuration line by line and I can't find anything in the live server setup that is different from the local which might affect it. Could gmail have black-listed my...
6
8296
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 the POST request, so how can I invoke this request directly from a PHP script?
0
9908
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9760
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10695
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9530
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7090
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4172
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3198
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.