UnitedForums - UK Web Hosting Forum UnitedHosting Community Hosting Forums
Network and Server StatusCustomer SupportUK Web Hosting
UnitedHostingUnitedHosting Sitemap UK Hosting ForumUK Web HostingWeb Hosting ForumsUK Reseller HostingWeb Host CommunityUK Managed Dedicated ServersHosting Help and SupportUK Domain Name Registration

Go Back   UnitedForums.co.uk > UnitedHosting Community > Website Development & Scripting

Reply
 
Thread Tools Rate Thread Display Modes
Old 30th July 2008, 12:00 PM   #1 (permalink)
richardhall
Registered User
 
Join Date: Oct 2003
Location: Stoke-on-Trent, UK
Posts: 54
Send a message via MSN to richardhall Send a message via Skype™ to richardhall
Question How to retrieve Raw HTTP Post Data in PHP

How can I get the raw HTTP post data from within PHP on UH servers?

So far I've tried:
$postdata = @file_get_contents( 'php://input' );
$postdata = $HTTP_RAW_POST_DATA;
$postdata = $_GLOBALS["HTTP_RAW_POST_DATA"];
But no luck so far- all return a zero bytes length string.

And my PHP.ini file reflects the following setting already (in case you were going to suggest it):
always_populate_raw_post_data = On

Any help appreciated.

Thanks,
richardhall is offline   Reply With Quote
Old 30th July 2008, 01:17 PM   #2 (permalink)
knapper
Senior Member
 
Join Date: Jun 2006
Location: Co. Durham
Posts: 107
You need to use:

$data = file_get_contents('php://input');

which I just tested.
knapper is offline   Reply With Quote
Old 30th July 2008, 01:27 PM   #3 (permalink)
richardhall
Registered User
 
Join Date: Oct 2003
Location: Stoke-on-Trent, UK
Posts: 54
Send a message via MSN to richardhall Send a message via Skype™ to richardhall
Thats basically the same as with the @ sign in front. Returns nothing. I'm posting XML data not form data if that makes any difference. I'm using this format to make my HTTP POST:

POST / HTTP/1.1
Host: api.hostnamehere.com
User-Agent: UserAgentHere/1.0.00
Content-Type: application/xml; charset=utf-8
Content-Length: 0

<?xml version="1.0" encoding="UTF-8"?>
<request>
<question1 param="value" />
<question2 param="value" />
<question3 param="value" />
</request>

But from the PHP script I post it to, I can't see any of the XML using file_get_contents or any of the other methods above.
richardhall is offline   Reply With Quote
Old 30th July 2008, 01:44 PM   #4 (permalink)
knapper
Senior Member
 
Join Date: Jun 2006
Location: Co. Durham
Posts: 107
Quote:
Originally Posted by richardhall View Post
Thats basically the same as with the @ sign in front. Returns nothing. I'm posting XML data not form data if that makes any difference.
Yes it does. The encoding type is critical. For example forms need to be application/x-www-form-urlencoded not multipart/form-data. Anyway, try changing Content-Type:application/xml to Content-Type:text/xml on your HTTP POST.

Edit:

Actually a bit more poking aound shows changing the Content-Type probably won't sort it but it's worth a shot. Either way php://input is the what you want.

Last edited by knapper : 30th July 2008 at 02:01 PM. Reason: grammer and added info
knapper is offline   Reply With Quote
Old 30th July 2008, 03:21 PM   #5 (permalink)
percepts
Senile Member
 
percepts's Avatar
 
Join Date: Mar 2005
Posts: 1,009
I'm not clear on what you want to do here. Are you just trying to pick up some unknown variables or to get the header records?
__________________
An old dog learning new tricks
percepts is offline   Reply With Quote
Old 30th July 2008, 03:32 PM   #6 (permalink)
Alex.
Registered User
 
Join Date: Jun 2007
Location: UK
Posts: 108
Send a message via MSN to Alex.
I think he's trying to access the xml being posted to the page. I've looked on some other websites, but they all seem to be using the techniques that you've tried.

As a wild stab in the dark, does increasing the value of Content-Length change anything?
Alex. is offline   Reply With Quote
Old 30th July 2008, 05:42 PM   #7 (permalink)
richardhall
Registered User
 
Join Date: Oct 2003
Location: Stoke-on-Trent, UK
Posts: 54
Send a message via MSN to richardhall Send a message via Skype™ to richardhall
knapper: I wondered that so i've tried changing the Content-Type to a whole variety of different things and it but seems to make no ounce of difference. Behaves the same both ways.

percepts: Alex is right I want to be able to process the XML in my PHP script and then output a response XML message. An implementation similar to XML-RPC or SOAP.

Alex: If I increase the Content-Length from zero then I get HTTP 400 Bad Request response and nothing in the raw HTTP POST data again.
richardhall is offline   Reply With Quote
Old 30th July 2008, 06:32 PM   #8 (permalink)
percepts
Senile Member
 
percepts's Avatar
 
Join Date: Mar 2005
Posts: 1,009
Yes but does the post data contain the actual xml or does it contain the url of the xml file which seem to be trying to read and if so, where is that xml file?
__________________
An old dog learning new tricks
percepts is offline   Reply With Quote
Old 31st July 2008, 11:53 AM   #9 (permalink)
richardhall
Registered User
 
Join Date: Oct 2003
Location: Stoke-on-Trent, UK
Posts: 54
Send a message via MSN to richardhall Send a message via Skype™ to richardhall
percepts: Nope its not uploading a file, the raw data text itself contains the XML.

all: No worries I got it all working now. Alex you got it- I couldn't just change the Content-Length to any value though it had to be EXACTLY the length of the XML content in bytes minus any leading or trailing spaces, carriage returns and line feeds. All works now. Ta very much!
richardhall is offline   Reply With Quote
Old 31st July 2008, 12:18 PM   #10 (permalink)
Simon
Dedicated to life!
 
Simon's Avatar
 
Join Date: Jul 2005
Location: 36°38'4.48"N - 4°42'18.52"W
Posts: 2,058
Send a message via MSN to Simon Send a message via Yahoo to Simon Send a message via Skype™ to Simon
the other option is to just remove the content length completly....
__________________
Freelance PHP Programming
__________________
Simon is offline   Reply With Quote
Old 31st July 2008, 01:39 PM   #11 (permalink)
richardhall
Registered User
 
Join Date: Oct 2003
Location: Stoke-on-Trent, UK
Posts: 54
Send a message via MSN to richardhall Send a message via Skype™ to richardhall
Wouldn't work without it!
richardhall is offline   Reply With Quote
Reply


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

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

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


All times are GMT. The time now is 05:05 PM.

UK Web Hosting  |  UK Reseller Hosting  |  UK Dedicated Servers UnitedHosting  |  UnitedSupport  |  UnitedForums  |  SEO by vBSEO 3.0.0
Copyright © 1998-2008 United Communications Limited. All Rights Reserved. Registered in England and Wales 3651923 - VAT Reg No. 737662309