WSDL 为了 PHP 从 basic 授权

我需要建立 php 课题 WSDL, 这是站立基本身份验证。

他有很多名称空间,所以似乎手动做到这一点。

我尝试了几个工具,但似乎身份验证会话不存在。
已邀请:

冰洋

赞同来自:

$options = array/
'login' => $username,
'password' => $password,
/;
$client = new SoapClient/$wsdl, $options/;


是的,它有效! 我试图使用我创建的解决方案,它连接到我的客户端。 WS, 哪个工作。 HTTP Basic Auth.

风见雨下

赞同来自:

HTTP Auth 与客户合作 SOAP, 但是,您无法访问密码受保护的文件。 WSDL

厘米
https://bugs.php.net/bug.php?id=27777

奔跑吧少年

赞同来自:

使用内置客户端 SOAP, 你必须有这样的东西:


$options = array/
'login' => $username,
'password' => $password,
/;
$client = new SoapClient/$wsdl, $options/;

喜特乐

赞同来自:

我解决了这个问题 lib
http://sourceforge.net/projects/nusoap/
. 让我们看看它是否有帮助


$params = array/
"param" => "value"
/;

$soap_client = new nusoap_client/$wsdl_url, true/;
$soap_client->setCredentials/USER_SERVICE, PASS_SERVICE, 'basic'/;
$soap_client->soap_defencoding = 'UTF-8'; //Fix encode erro, if you need
$soap_return = $soap_client->call/"method_name", $params/;

裸奔

赞同来自:

这个解决方案怎么样:

加载文件。 WSDL 并将其保存在本地文件中

创建 SoapClient 使用本地文件

那样的东西 /简化版本/ :


class MySoap {

private $WSDL = 'https://secure-wsdl.url?wsdl';

private $USERNAME = 'dummy';
private $PASSWORD = 'dummy';

private $soapclient;

private function localWSDL//
{
$local_file_name = 'local.wsdl';
$local_file_path = 'path/to/file/'.$local_file_name;

// Cache local file for 1 day
if /filemtime/$local_file_path/ < time// - 86400/ {

// Modify URL to format http://[username]:[password]@[wsdl_url]
$WSDL_URL = preg_replace/'/^https:\/\//', "https://{$this->USERNAME}:{$this->PASSWORD}@", $this->WSDL/;

$wsdl_content = file_get_contents/$WSDL_URL/;
if /$wsdl_content === FALSE/ {

throw new Exception/"Download error"/;
}

if /file_put_contents/$local_file_path, $wsdl_content/ === false/ {

throw new Exception/"Write error"/;
}
}

return $local_file_path;
}

private function getSoap//
{
if / ! $this->soapclient /
{
$this->soapclient = new SoapClient/$this->localWSDL//, array/
'login' => $this->USERNAME,
'password' => $this->PASSWORD,
//;
}

return $this->soapclient;
}

public function callWs// {

$this->getSoap//->wsMethod//;
}
}


这个对我有用 :/

卫东

赞同来自:

这是使用Web服务身份验证的简单示例 soapClient


$apiauth =array/'UserName'=>'abcusername','Password'=>'xyzpassword','UserCode'=>'1991'/;
$wsdl = 'http://sitename.com/service.asmx?WSDL';
$header = new SoapHeader/'http://tempuri.org/', 'AuthHeader', $apiauth/;
$soap = new SoapClient/$wsdl/;
$soap->__setSoapHeaders/$header/;
$data = $soap->methodname/$header/;


此代码内部将标题拆卸如下。


<soap:header>
<authheader xmlns="[url=http://tempuri.org/">]http://tempuri.org/">[/url]
<username>abcusername</username>
<password>xyzpassword</password>
<usercode>1991</usercode>
</authheader>
</soap:header>

卫东

赞同来自:

我试图解决这个问题,但据我所知,客户端连接 soap 使用SSL + HTTPAUTH Web服务,它甚至很痛苦。 我Googleled,从我理解的问题解决时,你可以使用以下示例来解决和您的问题/使用 HttpAuth infos 如在设置中 url, 在设置中 soapClient/.


$username="test";
$password="test";
$url = "[url=https://".urlencode/]https://".urlencode/[/url]$username/.":".urlencode/$password/."@example.com/service.asmx?WSDL";

$context = stream_context_create/[
'ssl' => [
// set some SSL/TLS specific options
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
]]/;

$client = new SoapClient/$url, [
'location' => $url,
'uri' => $url,
'stream_context' => $context,
'login' => $username,
'password' => $password
]/;

$params=array/
'operation'=>’arguments',
'and’=>'other bull',
'goes’=>'here'
/;

$response = $client->__soapCall/'OperationName', array/$params//;

要回复问题请先登录注册