...

View Full Version : xml base64 php



naf
07-06-2008, 01:41 AM
hi..

just joined . hi to everyone.

I am trying to setup a xml for a friend of mine.. the source is a remote http server ...and you can send differnt api request to it and you recieve a responce depending on the request.

In the api documentation it says the userid and login id must be base 64 encoded..The api request query i send to the remote server I encode the userid and login id.

I am trying to echo the responce and all get is encoded message.I am been trying to figure out what i need to do to encode it.i tried echo base64_decode($str); but all i get is blank page ..if i do just echo $responce then i get a responce but is un readable.

here is the code ii am trying to use.i am usng php 5



<?php
$service_url = "https://remote.server.com"; ?>
<?php
$xml = '<apiRequest xmlns="API_Request_ProductDetails"> <header> <apiVersion>1</apiVersion> <userID>base64 encoded</userID> <loginGUID>base64 encoded</loginGUID> </header> <request> <searchRequest> <itemcode>item no1</itemcode> </searchRequest> </request> </apiRequest>';?>


<?php
// set curl header options
$curl_header = "POST “.$service_url.” HTTP/1.0 \r\n";
$curl_header .= "MIME-Version: 1.0 \r\n";
$curl_header .= "Content-type: application/PTI26 \r\n";
$curl_header .= "Content-length: ".strlen($xml)." \r\n";
$curl_header .= "Content-transfer-encoding: text \r\n";
$curl_header .= "Request-number: 1 \r\n";
$curl_header .= "Document-type: Request \r\n";
$curl_header .= "Interface-Version: Test 1.4 \r\n";
$curl_header .= "Connection: close \r\n\r\n";
$curl_header .= $xml;// add xml to header
$curl = curl_init();// create curl handler
// set curl options
curl_setopt($curl, CURLOPT_URL, $service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $curl_header);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($curl);// execute the curl request
if(curl_errno($curl)){// check for error in processing curl request
exit;
}
curl_close($curl);// close the curl connection
?>

<?php


//process the returned ****ty xml
echo $response;

//print $response;
//$str = $response;
//echo base64_decode($str);

?>



i am still learning php. if i have messed up on something do let me know.
kind regards

shyam
07-06-2008, 08:28 PM
have you tried sending a normal post request instead of a custom request


$curl_header_arr = array(
"MIME-Version: 1.0 \r\n",
"Content-type: application/PTI26 \r\n",
"Content-transfer-encoding: text \r\n",
"Request-number: 1 \r\n",
"Document-type: Request \r\n",
"Interface-Version: Test 1.4 \r\n",
"Connection: close \r\n\r\n"
);
$curl_header .= $xml;// add xml to header
$curl = curl_init();// create curl handler
// set curl options
curl_setopt($curl, CURLOPT_URL, $service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $curl_header_arr);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
$response = curl_exec($curl);// execute the curl request

naf
07-06-2008, 09:49 PM
thanks for replying.. i get a this error message if i try normal post request

" Blank xml document or invalid xml structure ".

If i try my orignal method.i do get a response from the remote server but it is all encoded..looking at the view source this is what i see.i am pasting just a part of it..


</element>
</attributes>
<specification>
<spec_element>
<spec_title>S2V5Ym9hcmQ=</spec_title>
<spec_description>TnVtYmVyIG9mIEtleXM=</spec_description>
<spec_value></spec_value>
</spec_element>

<spec_element>
<spec_title>S2V5Ym9hcmQ=</spec_title>
<spec_description>TnVtYmVyIG9mIEhvdGtleXM=</spec_description>
<spec_value></spec_value>
</spec_element>
<spec_element>
<spec_title>S2V5Ym9hcmQ=</spec_title>

<spec_description>SW50ZXJuZXQgS2V5</spec_description>
<spec_value></spec_value>
</spec_element>
<spec_element>
<spec_title>S2V5Ym9hcmQ=</spec_title>
<spec_description>U2NyZWVuIExvY2sgS2V5</spec_description>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum