PHP SOAP不包括我的请求
问题描述:
参数我试图访问PHP SOAP不包括我的请求
https://statistik.uni-c.dk/instregws/DataServiceXML.asmx?op=HelloWorldCredentials
我有必要的凭证HelloWorldCredentials服务。
据我所见,我需要提交一个名为“Credentials”的数组,其中包含一个包含两个字符串的数组,一个名为“Username”,另一个名为“Password”。
我建我的数组是这样的:
$params = array(
"Credentials" => array(
"Username" => "Obviously",
"Password" => "NotPublic",
)
);
然而,当我执行
$client = new SoapClient("https://statistik.uni-c.dk/instregws/DataServiceXML.asmx?wsdl", array('trace' => 1));
$params = array(
"Credentials" => array(
"Username" => "Obviously",
"Password" => "NotPublic",
)
);
$response = $client->__soapCall("HelloWorldCredentials", array($params));
echo("*** PARAMS ***\n");
var_dump($params);
echo("\n*** REQUEST ***\n");
echo($client->__getLastRequest());
echo("\n*** RESPONSE ***\n");
var_dump($response);
我得到
*** PARAMS ***
array(1) {
["Credentials"]=>
array(2) {
["Username"]=>
string(11) "Obviously"
["Password"]=>
string(8) "NotPublic"
}
}
-as我应该,但
*** REQUEST ***
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://statistik.uni-c.dk/instreg/">
<SOAP-ENV:Body>
<ns1:HelloWorldCredentials/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
所以,很显然,我得到
*** RESPONSE ***
object(stdClass)#3 (1) {
["HelloWorldCredentialsResult"]=>
string(19) "Missing credentials"
}
为什么是我的参数从请求完全不存在?
答
根据WSDL为HelloWorldCredentials方法,你需要发送证书在Header
没有肥皂Envelope
的Body
所以这应该工作:
<?php
$client = new SoapClient("https://statistik.uni-c.dk/instregws/DataServiceXML.asmx?wsdl", array('trace' => 1));
$credentials = array(
'Username' => 'Obviously',
'Password' => 'NotPublic'
);
$header = new SoapHeader('http://statistik.uni-c.dk/instreg/', 'Credentials', $credentials);
$client->__setSoapHeaders($header);
$response = $client->HelloWorldCredentials();
echo("\n*** REQUEST ***\n");
echo($client->__getLastRequest());
echo("\n*** RESPONSE ***\n");
var_dump($response);
尔加。非常感谢! :-)他们为什么要把它放在标题中? – OZ1SEJ