...

View Full Version : Receiving XML response in php script (encoding.com)



aaronrab
05-07-2009, 07:15 AM
Hi,
I'm trying to utilize information in an XML response from encoding.com

once encoding has finished converting a file, it sends and HTTP POST request to a php script for me. I'm having trouble accessing the POST info.

have tried
file_get_contents('php://input'); but that didn't work for me.

i've run the rest of my script accessing the info from a .xml file and it worked fine so my issue is just figuring out how to get the xml in the POST.

Encoding.com api is here (http://www.encoding.com/wdocs/ApiDoc).

Thanks!

Fumigator
05-07-2009, 03:40 PM
Have you tried the process encoding.com demonstrates in the sample PHP script?

http://www.encoding.com/wdocs/SampleScripts#php

aaronrab
05-07-2009, 05:10 PM
Hi, thanks for the response. I have used the sample script as a model for my initial request and that is working fine, I have no trouble capturing that initial response. The response I'm having trouble with is the response they send minutes or hours later when the video has been encoded.

Maybe you're saying I can use the same method? curl? This is the part I'm confused on. I have RTFM, but it seems they don't address the what I'm trying to do, or they do and it's just not explicit and I'm not making the connection.

Any other comments you have would be appreciated. Thanks!

Fumigator
05-07-2009, 08:10 PM
Yeah it seemed to be a little fuzzy on the website how to catch that, but if it's just a normal HTTP POST request, PHP will put the info in the $_POST array and you'll be able to create an XML object from the $_POST array. The POST request is sent to a specific script on your website I assume?

aaronrab
05-07-2009, 10:47 PM
okay, some progress! using:


$response = $_POST['xml'];

I'm getting this:


<?xml version="1.0"?>
<result><mediaid>179962</mediaid><source>http://santamonica.s3.amazonaws.com/src/3c8797fe12a3</source><status>Finished</status><description></description><format><taskid>637094</taskid><output>flv</output><status>Finished</status><destination>http://santamonica.s3.amazonaws.com/enc/3c8797fe12a3.flv?acl=public-read</destination></format></result>

I need to get the value enclosed in the source tags and eventually the destination tags.

I'm trying:

$response = $_POST['xml'];
$doc= new DOMDocument();
$doc->loadXML($response);
$sourceNode = $doc->getElementsByTagName("source");
$source = $sourceNode->item(0)->nodeValue;

but this doesn't seem to be grabbing the source value.

Can you see what I'm screwing up?

Fumigator
05-08-2009, 06:02 AM
I've never dealt with the DOM Document object but it looks pretty cool! I can see the example in the PHP manual you used as a template and it looks to me like you're doing everything right. So.. :confused:

Try print_r() on the objects in question to see if they are built the way we think they should be built.

oesxyl
05-08-2009, 07:06 AM
$response = $_POST['xml'];
$doc= new DOMDocument();
$doc->loadXML($response);
$sourceNode = $doc->getElementsByTagName("source");
$source = $sourceNode->item(0)->nodeValue;

but this doesn't seem to be grabbing the source value.

check if $doc, $sourceNod and $source are null or not, also check with $sourceNode->length if node list is empty or not.

best regards

aaronrab
05-11-2009, 06:57 PM
Thanks to both of you for responding. I finally gave in and went with a workaround. Kind of irritates me, but at least the situation made one available.
Thanks,
Aaron



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum