Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 19-02-06
chs's Avatar
chs chs is online now
Now then
 
Join Date: Oct 2005
Location: Newcastle Upon Tyne
Posts: 234
Thanks: 0
Thanked 3 Times in 3 Posts
chs is an unknown quantity at this point
  HTTP POST in PHP

I am trying to do a HTTP POST within php code but instead of getting the HTML source of the page I am posting to I just get the HTTP header back e.g.

Code:
HTTP/1.1 200 OK
Content-Type: text/html
Date: Sun, 19 Feb 2006 15:32:33 GMT
Server: Apache Coyote/1.0
Connection: close
Here's my code:

PHP Code:
$content "";
$post_query "name=".$_POST['name'];
$post_query urlencode($post_query) . "\r\n";
$host "test.domain.co.uk";
$path "/details";
$fp fsockopen($host"80");
if (
$fp
{
    
fputs($fp"POST ".$path." HTTP/1.0\r\nHost: ".$host."\r\n");
    
fputs($fp"Content-type: application/x-www-form-urlencoded\r\n");
    
fputs($fp"Content-length: "strlen($post_query) ."\r\n\r\n");
    
fputs($fp$post_query);

    while (!
feof($fp)) 
    {
        
$content .= fgets($fp4096);
    }


print_output($content); 
What I'd like is $content to contain the HTML source of the page. Does anyone know how this can be done?

Cheers,

Dan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 19-02-06
Registered User
 
Join Date: Mar 2004
Location: Reading, UK
Posts: 301
Thanks: 0
Thanked 0 Times in 0 Posts
dmorison is an unknown quantity at this point
Just a long-shot; but as the Host header isn't officially part of HTTP 1.0 (it came in at 1.1) try changing your request to send "HTTP/1.1".

If it does make a difference and you are able to get the full response; any strange characters would indicate a chunked encoded response...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 19-02-06
Aquanuke's Avatar
ShagaaDaggaDoo
 
Join Date: Aug 2003
Location: Surrey
Posts: 1,116
Thanks: 0
Thanked 0 Times in 0 Posts
Aquanuke is an unknown quantity at this point
Is fsockopen allowed on your server?

I think SELinux comes as default these days which disables sockets.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 20-02-06
chs's Avatar
chs chs is online now
Now then
 
Join Date: Oct 2005
Location: Newcastle Upon Tyne
Posts: 234
Thanks: 0
Thanked 3 Times in 3 Posts
chs is an unknown quantity at this point
Thanks for the replies guys, fsockopen is enabled.

I tried changing to HTTP 1.1 and although it still didn't work the header changed to:

Code:
HTTP/1.1 200 OK
Content-Type: text/html
Transfer-Encoding: chunked
Date: Mon, 20 Feb 2006 08:31:09 GMT
Server: Apache Coyote/1.0
Note the addition of Transfer-Encoding: chunked. What exactly does this mean?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 20-02-06
Registered User
 
Join Date: Mar 2004
Location: Reading, UK
Posts: 301
Thanks: 0
Thanked 0 Times in 0 Posts
dmorison is an unknown quantity at this point
Chuncked encoding is a mechanism in HTTP/1.1 that enables large documents to be transferred in "chunks" and for the transfer to be resumed if the connection drops. This is how Internet Explorer (and other browsers) are able to pick-up on a large download.

As I understand it; chunked encoding is a mandatory requirement of a HTTP/1.1 compatible client; and therefore you cannot indicate that you will not accept it as part of the request. However, it is not part of HTTP/1.0; and therefore if you send a 1.0 request you will not get a chunked encoded response. Luckily; the "Host" header is widely implement with disregards to the HTTP version; so you should be OK.

That doesn't explain why you're not getting the whole document though. Are you doubly sure that that you are POST'ing the correct parameters and action URL in order to get a response....?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 20-02-06
Super Moderator
 
Join Date: Aug 2003
Posts: 2,451
Thanks: 0
Thanked 0 Times in 0 Posts
Rich is an unknown quantity at this point
I'm not sure why you are getting no document body, but normally the headers and document contents come in in the same stream so the most likely reason is the webserver isn't sending any contents. This could be down to your POST request being invalid or the server is set up to serve different content to different browsers (faily common on aspx pages) and it can't decide what browser you are.

I can't help with the first bit, but to make your request look a bit more like its coming from a regular browser you could try adding the following headers into your request
PHP Code:
fputs($fp"Accept: */*\r\n");
fputs($fp"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1\r\n"); 
I just noticed one other thing. I think you need to send a blank line to indicate you have finished sending request headers, that would possibly account for what you are getting back. Just send another \r\n after the post_query.

Hope that helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Spammy Tags <!-- ANY GOOD ? --> futureweb The Affiliate Marketing Lounge 16 01-09-06 07:20 PM
Anyone anygood with xml, php, mysql and Affiliate Window AnnonnyMouse The Affiliate Marketing Lounge 1 23-09-04 11:00 AM
PHP - No input file specified. - Problem Barry Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 1 02-08-04 10:57 AM
PHP or Browser Timeout? Barry Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 6 28-04-04 01:04 PM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7