Php Soap客户端,如何使用基本HTTP身份验证通过HTTPS调用函数

Php Soap客户端,如何使用基本HTTP身份验证通过HTTPS调用函数,php,basic-authentication,soap-client,nusoap,Php,Basic Authentication,Soap Client,Nusoap,这个问题已经折磨了我一整天了 我有一个客户端web服务https://*.asmx?WSDL,具有基本的HTTP身份验证 如果我使用SoapUI连接到Web服务,那么一切都会完美无误 问题是当我切换到PHP时 我设法连接到它,我可以使用soapclient extension for php(我使用的是PHP5.3.0)从服务器获取函数列表 当我尝试使用PHP的soapclient扩展调用函数时,出现以下错误: 致命错误:未捕获的SoapFault异常:[HTTP]在中获取HTTP头时出错 C:

这个问题已经折磨了我一整天了

我有一个客户端web服务https://*.asmx?WSDL,具有基本的HTTP身份验证

如果我使用SoapUI连接到Web服务,那么一切都会完美无误

问题是当我切换到PHP时

我设法连接到它,我可以使用soapclient extension for php(我使用的是PHP5.3.0)从服务器获取函数列表

当我尝试使用PHP的soapclient扩展调用函数时,出现以下错误:

致命错误:未捕获的SoapFault异常:[HTTP]在中获取HTTP头时出错 C:\www\xpto\u Atestes\soapclient.php:26堆栈跟踪:#0[内部函数]:>soapclient->uu-doRequest('***…','http://*********..',1,0)#1>C:\www\xpto\u Atestes\soapclient.php(26):soapclient->u-soapCall('login',Array)#2{main}>在第26行的C:\www\xpto\u-Atestes\soapclient\soapclient.php中抛出

更明确的错误(当我打印调用结果时):

[faultstring]=>获取http头时出错
[faultcode]=>HTTP

正在发送以下标头:

POST/*.asmx HTTP/1.1主机:*.pt连接:保持活动用户代理:>PHP-SOAP/5.3.0内容类型:text/xml;charset=utf-8 SOAPAction:“http://***/Login”>内容长度:264授权:基本AUTHSECRETPASS

我这样称呼它:

$soapParams=array('login'=>'HTTP\u login',
“密码”=>“HTTP_PASS”,
“身份验证”=>SOAP\u身份验证\u基本,
“跟踪”=>1,
“例外情况”=>0
);
$client=新的SoapClient(“https://***.asmx?WSDL”,$soapParams); 回声“已连接
”; $params=array('account'=>'','msisdn'=>'NUMBER','password'=>'password'); $result=$client->\uuu soapCall(“login”,$params)

在谷歌搜索了一段时间并试图找出问题所在后,我转向了nusoap。。这也给了我一个错误:

错误

HTTP错误:套接字读取标头超时

请求

POST/**.asmx HTTP/1.0 主机:*.pt 用户代理:NuSOAP/0.9.5(1.123) 内容类型:text/xml;字符集=ISO-8859-1 SOAPAction:“http://***/Login” 授权:基本AUTHSECRETPASS 内容长度:481

数字密码

响应

我这样称呼它:

$client=new nusoap_client(“https://**.asmx?WSDL”,true)
$client->setCredentials('HTTPUSER','HTTPPASS','basic')
$params=数组( '帐户'=>'', 'msisdn'=>'NUMBER', '密码'=>'密码' );
$result=$client->call('Login',$params)

使用nusoap,我还尝试启用curl扩展来进行调用:

$client->setUseCurl(true)

但没有这样的运气,它不断地出错:

HTTP错误:cURL错误:56:从对等方接收数据时失败 url:http://*********.asmx
内容类型:
http_代码:0
标题大小:0
请求大小:750
文件时间:-1
ssl验证结果:0
重定向\u计数:0
总时间:21.015
名称查找时间:0
连接时间:0
预转移时间:0
上传大小:462
下载大小:0
下载速度:0
上传速度:21
下载内容长度:-1
上传内容长度:-1
开始传输时间:0
重定向时间:0

我100%确信webservice没有任何问题,如果我可以从SoapUI调用它而没有任何问题,我不明白为什么我不能从PHP调用它

我不知道我还能做什么。。我想我什么都试过了

编辑:我刚刚尝试了另一个用于PHP的Soap类,这次来自Zend

结果是:

致命错误:未捕获的SoapFault异常:[WSDL]SOAP-error:解析WSDL:无法从“https://***.asmx?WSDL”加载:未能加载C:\www\xpto\u Atestes\Zend\SOAP\Client\Common.php:51堆栈跟踪中的外部实体“https://*.asmx?WSDL”: #0 C:\www\xpto\u Atestes\Zend\Soap\Client\Common.php(51):SoapClient->SoapClient('https://***..,数组)
#1 C:\www****\u Atestes\Zend\Soap\Client.php(1032):Zend\u Soap\u Client\u Common->\u构造(数组,'https://**..,数组)
#2 C:\www****\u Atestes\Zend\Soap\Client.php(1188):Zend\u Soap\u Client->\u initSoapClientObject()
#3 C:\www***\u Atestes\Zend\Soap\Client.php(1112):Zend\u Soap\u Client->getSoapClient()#4[内部函数]:Zend\u Soap\u Client->\u调用('Login',Array)
#5 C:\www****\u Atestes\zend.php(28):zend\u Soap\u客户端->登录(数组)
#6{main}被抛出


我只想回答我自己,以防其他人也想知道我是如何解决的

问题在于,其中一个Web服务的请求XML必须采用以下格式:

<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns123:IsTokenValid xmlns:ns123="http://www.xxxxxxx.com">
            <ns123:token xsi:type="xsd:string">'.$this->loginToken.'</ns123:token>
        </ns123:IsTokenValid>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Iain和其他人,希望这是清楚的。

你好Tio我有完全相同的问题(尝试Zend和NuSoap但没有成功),你成功地让它工作了吗?谢谢,伊夫。@yjusot。。嗯,我设法用NuSoap解决了这个问题,Web服务的WSDL要求各个字段都有前缀,而NuSoap没有把它们放进去。。因此,我更改了NuSoap上的代码,将前缀添加到字段中,但我建议您使用$client->send方法,在该方法中,您可以将请求XML作为参数传递,这样您就不需要更改任何内容。。如果你需要一个例子,说点什么。你能再详细介绍一下你的解决方法吗?i、 什么前缀?
$nsValue = rand(1000, 9000);
$requestXml = '<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns'.$nsValue.':IsTokenValid xmlns:ns'.$nsValue.'="http://www.xxxxxxx.com">
<ns'.$nsValue.':token xsi:type="xsd:string">'.$this->loginToken.'</ns'.$nsValue.':token>
</ns'.$nsValue.':IsTokenValid>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
$result = WebService::CallWebService($this->endPoint, 'http://www.xxxxxxx.com/IsTokenValid', $requestXml, $this->httpUser, $this->httpPass);
$client = new nusoap_client($webServiceLink, false);
$result = $client->send($request, $soapAction, '', self::$timeout, self::$responseTimeout);