warmwinter / hessianphp

Automatically exported from code.google.com/p/hessianphp
MIT License
0 stars 0 forks source link

Basic Auth using CURL Options #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following code will not auth correctly. if I use the standard PHP CURL 
functions it works. but in HessianPHP it doesn't

<?php
require("hessian/HessianClient.php");

$url = 'http://subetha.lbmv.de/api/Admin';

$curl_options = array(
        "CURLOPT_URL, $url",
        "CURLOPT_RETURNTRANSFER, 1",
        "CURLOPT_USERPWD, 'admin_user@domain.tld:password'",
        "CURLOPT_USERAGENT, 'subetha subscription script/1.0 (PHP)'",
        "CURLOPT_TIMEOUT, 10",
        "CURLOPT_FOLLOWLOCATION, 1"
);

$options = new HessianOptions();
$options->transport = "CURL";
$options->transportOptions = $curl_options;

// Subetha getLists class lists all mailing lists available
// public List<ListData> getLists(int skip, int count);
class getLists{
        var $skip;
        var $count;
}

$lists = new getLists();

$proxy = new HessianClient($url, $options);
try{
    echo $proxy->getLists(2,5); 
} catch (Exception $ex){
   // ...handle error
        echo "error: ".$ex;
        exit;
}

?>

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by t00_m4d_f00@web.de on 9 Jun 2010 at 7:14

GoogleCodeExporter commented 9 years ago
sorry.

latest HessianPHP with PHP 5.3.2-1 on debian Lenny accessing Subetha running on 
Resin 4.0

I get the following error:

root@contra:/var/www/www-doku.lbmv.de/srv/www/doku2/dirLIST_files# php 
subscribe_user.php 
Calling method: getListserror: exception 'HessianFault' with message 
'permission denied' in 
/var/www/www-doku.lbmv.de/srv/www/doku2/dirLIST_files/hessian/Hessian2/Hessian2S
erviceParser.php:66
Stack trace:
#0 
/var/www/www-doku.lbmv.de/srv/www/doku2/dirLIST_files/hessian/Hessian2/Hessian2S
erviceParser.php(32): Hessian2ServiceParser->parseFault()
#1 
/var/www/www-doku.lbmv.de/srv/www/doku2/dirLIST_files/hessian/HessianClient.php(
69): Hessian2ServiceParser->parseTop()
#2 
/var/www/www-doku.lbmv.de/srv/www/doku2/dirLIST_files/hessian/HessianClient.php(
85): HessianClient->__hessianCall('getLists', Array)
#3 [internal function]: HessianClient->__call('getLists', Array)
#4 
/var/www/www-doku.lbmv.de/srv/www/doku2/dirLIST_files/subscribe_user.php(60): 
HessianClient->getLists(2, 5)
#5 {main}

Original comment by t00_m4d_f00@web.de on 9 Jun 2010 at 7:17

GoogleCodeExporter commented 9 years ago
Hello

I believe there is a mistake in the sintax you are using to define the CURL 
options in the array. According to the manual, you should use an associative 
array in which the keys are the option constants and the values are mixed, 
depending on the option. 
Internally, the curl_setopt_array() function its used and the options are 
merged with defaults.

For example, in order to access a site with BASIC authentication enabled using 
CURL transport, you would do something like this:

$options = new HessianOptions();
$options->transportOptions = array( CURLOPT_USERPWD => 'user:password' );
$proxy = new HessianClient($url, $options);
...

Sometimes, it's actually clearer/shorter to use the array sintax all along, 
like this:

// this is the same basic authentication but using the http streams transport
$options = array(
    'transport' => 'http', 
    'header' => array("Authorization: Basic ".base64_encode('user:password'))
);
$proxy = new HessianClient($url, $options);

You don't need to redefine options such as CURLOPT_RETURNTRANSFER or 
CURLOPT_URL, because those are set by default in the transport class.

I have enhanced the error reporting in the transport classes to make it clearer 
when something like this happens, I will write more documentation regarding 
this shortly

Original comment by vegeta...@gmail.com on 17 Jun 2010 at 6:20