Read XML that is POSTed
- Started
- Last post
- 15 Responses
- must_dash
How do i do this with PHP?
I'm trying to use this to get the original data...
$data = trim(file_get_contents('php://in...
but not grabbing it correctly, any ideas?
- Shaney0
PHP 4 or 5, are you using simplexml in 5 or nusoap or similar in 4?
- must_dash0
I'm using PHP Version 5.2.5 and the code I have I'm using it with a simple parser which works with a text file... but not with POST data
- acescence0
what content type header is getting sent? has to be text/xml
- must_dash0
Here is an example of it...
http://www.romancart.com/help/xm…
- must_dash0
Is it a utf-8 problem?
- acescence0
when php receives the post data, it won't work if the data is not encoded properly. how is the data posting to your script? you have to look at the headers from that post and see what is getting sent
- must_dash0
i have no control over the format of the data, is there a way of decoding utf-8 to text/xml
- acescence0
it's not a utf-8 issue, php can't handle an input stream if it is multipart/form-data encoded. of course, i'm just guessing this is your problem. can we see the actual post data?
- must_dash0
i've already posted it (i think!?)
- acescence0
that's just your static version though, no? you have to look at the data as sent in the actual post request.
- must_dash0
that is the form it takes, and is the same as the posted one, which i can only see when i make a transaction... think i'm just going to read the data is as text, and just find the strings i need... as only need a code for each product someone buys
- acescence0
when the server sends the xml, it sends a header along with it that says what format the request is in, you need to look at that bit of information, which is not in that static file. firebug or the safari developer console will let you look at headers. if it's multipart/form-data, php://input won't work, you have to use $HTTP_RAW_POST_DATA instead.
- & check $HTTP RAW POST DATA is set to 1 or on in php.ini. some hosts turn it offShaney
- welded0
XML in PHP5 is really easy. Simple, you might say.
$xml = simplexml_load_string( $_POST['your_xml'] );
Now $xml is a proper XML object so you can search it with xpath, iterate through and manipulate the nodes, and so on and so forth.
- vaxorcist0
you may have to wrap stuff in CDATA tags inside the XML
<name><![CDATA[ stuff with O'really apostrophe's and such! is here&!@!!$*!#! ]]></name>
- Shaney0
simple xml is the answer as welded said, i'd assumed this was being used when he said a simple parser, makes it very easy to pull whatever you want. This used to be a bit of a pain in php 4 as you had to use soap or similar, PHP 5 changed all that.