2017-08-29 43 views
0

參數我試圖訪問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" 
} 

爲什麼是我的參數從請求完全不存在?

回答

1

根據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); 
+0

爾加。非常感謝! :-)他們爲什麼要把它放在標題中? – OZ1SEJ