Page 1 of 1

xmp php base 64

Posted: Sat Jul 05, 2008 3:13 pm
by naf
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

Code: Select all

 
<html>
<body>
<?php
$service_url = "https://remote.server.com"; ?>
<?php
$xml = '<apiRequest xmlns="API_Request_get_details"> <header> <apiVersion>1</apiVersion> <userID>base64 encoded</userID> <loginGUID>base64 encoded</loginGUID> </header> <request> <searchRequest> <itemcode>part number</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 <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> xml 
echo $response;
 
//print $response;
//$str = $response;
//echo base64_decode($str);
 
 
?>
</body>
</html>
i am still learning php. if i have messed up on something do let me know.
kind regards

Re: xmp php base 64

Posted: Wed Jul 09, 2008 4:40 pm
by Benjamin
base64_decode is correct, assuming the data being returned is base64 encoded. A blank page means there was a parse or fatal error in your code. You'll want to enable error reporting or check your error log for details.

http://us.php.net/manual/en/function.er ... orting.php

Code: Select all

 
error_reporting(E_ALL);
ini_set('display_errors', true);