Zend Soap Client无法使用授权http标头

时间:2013-02-15 11:18:23

标签: zend-framework soap

我使用以下代码使用API​​从第三方网站中检索类别,但遗憾的是,流上下文无法在其API中请求并导致内部错误。

仅供参考:它在zend框架下使用。

$header = "Authorization: Bearer ".$accestoken."\r\n"."Content-Type:text/xml";//.'Content-Type:application/xml';

$wsdl = 'wsdl url';

$context = stream_context_create(array('http' => array('header' => $header,'method'=>'GET')));

             $options = array('stream_context'=>$context,'encoding'=>'ISO-8859-1','exceptions'=>FALSE);


            $params = array ('accessToken' => $accestoken);


            $response = $client->getAdCategories($params);

             print_r($response);

所以请找到上面的代码并为这个问题提供一些解决方案。

2 个答案:

答案 0 :(得分:1)

$httpHeaders = array(
            'http'=>array(
            'protocol_version' => 1.1,
            'header' => "Authorization:Bearer ".$accestoken."\r\n" ,
                    "Connection: close"
            ));


$context = stream_context_create($httpHeaders);

    $soapparams = array(                    
                                            'stream_context' => $context,

                            );
$client = new SoapClient($wsdl, $soapparams);
$response = $client->getAdCategories($params);

         print_r($response);

请参阅https://bugs.php.net/bug.php?id=49853

答案 1 :(得分:0)

好的,我在标题中看到至少这是您正在尝试使用的SOAP服务。然后你应该使用类似Zend_Soap_Client的东西。

看起来你有一个WSDL ......所以,

$client = new Zend_Soap_Client("yourwsdl.wsdl");

然后提出类似

的请求
$retval = $client->method1(10);

查看您的代码我不是100%确定正在使用的身份验证方法。如果是基本的HTTP身份验证,您只需将用户名和密码作为客户端构造函数中的选项传递。

设置标题可能如下所示:

$auth = new stdClass();
$auth->user = 'joe';
$auth->token = '12345'; 

$authHeader = new SoapHeader('authNamespace', 'authenticate', $auth);

$client->__setSoapHeaders(array($authHeader));

如果您需要更多帮助发布您的WSDL。