PHP SOAP在请求中不包括我的参数
我正在尝试访问上的HelloWorldCredentials服务PHP SOAP在请求中不包括我的参数,php,soap,Php,Soap,我正在尝试访问上的HelloWorldCredentials服务 https://statistik.uni-c.dk/instregws/DataServiceXML.asmx?op=HelloWorldCredentials 我有必要的证件 据我所知,我需要提交一个名为“Credentials”的数组,其中一个数组包含两个字符串,一个数组名为“Username”,另一个数组名为“Password” 我按如下方式构建阵列: $params = array( "Credentials"
https://statistik.uni-c.dk/instregws/DataServiceXML.asmx?op=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 );
我明白了
-我应该这么做,但是
*** 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>
为什么请求中完全没有我的参数?根据方法的WSDL,您需要在soap
信封的头中而不是正文中发送凭据
所以这应该是可行的:
<?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 );
1];
$credentials=数组(
“用户名”=>“显然”,
'密码'=>'不公开'
);
$header=新的SoapHeader('http://statistik.uni-c.dk/instreg/“,”凭证“,$Credentials);
$client->uu setSoapHeaders($header);
$response=$client->HelloWorldCredentials();
回音(“\n***请求***\n”);
echo($client->u getLastRequest());
回音(“\n***响应***\n”);
var_dump($response);
Gah。非常感谢!:-)他们为什么要把它放在标题里。。。?
*** RESPONSE ***
object(stdClass)#3 (1) {
["HelloWorldCredentialsResult"]=>
string(19) "Missing credentials"
}
<?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 );