Zend Soap客户端上的授权http标头不起作用



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

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

$header = "Authorization: Bearer ".$accestoken."rn"."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);

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

$httpHeaders = array(
            'http'=>array(
            'protocol_version' => 1.1,
            'header' => "Authorization:Bearer ".$accestoken."rn" ,
                    "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

好吧,我在标题中看到,至少这是一个您正在尝试使用的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。

最新更新