Soap身份验证标头和使用PHP的请求 [英] Soap authentication header and request using PHP
问题描述
我正在尝试为在线餐厅餐桌预订服务设置SOAP调用,但是无法使其正常工作.它使用身份验证标头,并尝试了以下代码,没有任何运气:
I am trying to setup a SOAP call for an online restaurant table booking service but haven't been able to get it working. It uses authentication header and have tried the following code without any luck:
$username = '';
$password = '';
$soapURL = "http://m.cmd-it.dk/reservations.asmx?WSDL";
$client = new SoapClient($soapURL,array());
$auth = array(
'UserName' => $username,
'Password' => $password,
'createReservation'=> array(
'reservation2CompanyName' => 'Tester',
'customerFirstName' => 'test',
'customerLastName' => 'tester',
'customerTelephoneNumber' => '22334455',
'customerMail' => 'test@example.com',
'reservationDate' => date("j/m/Y", time()),
'reservationTime' => date("H:i", time()),
'reservationPAX' => '3',
'reservationRemarks' => 'test',
'TestMode' => 1
)
);
$header = new SoapHeader('http://cmd-it.dk/','authentification',$auth,false);
$client->__setSoapHeaders($header);
echo var_dump($client->__getLastRequestHeaders());
echo var_dump($client->__getLastRequest());
但是它只是呼应的NULL NULL ...:-(
But it just echo's NULL NULL... :-(
我不熟悉 PHP SOAP 调用,也根本不使用身份验证标头,但希望有人能将我推向正确的方向.
I am not familiar with PHP SOAP calls and not at all using authentication headers, but hope somebody can push me in the right direction.
推荐答案
您即将达到目标.在这里,我修改了几行代码:
you was near to reach your goal. Here I have modified few lines of your code:
<?php
$username = '';
$password = '';
$soapURL = "http://m.cmd-it.dk/reservations.asmx?WSDL";
$client = new SoapClient($soapURL,array());
$auth = array(
'UserName' => $username,
'Password' => $password,
'createReservation'=> array(
'reservation2CompanyName' => 'Tester',
'customerFirstName' => 'test',
'customerLastName' => 'tester',
'customerTelephoneNumber' => '22334455',
'customerMail' => 'test@example.com',
'reservationDate' => date("j/m/Y", time()),
'reservationTime' => date("H:i", time()),
'reservationPAX' => '3',
'reservationRemarks' => 'test',
'TestMode' => 1
)
);
$header = new SoapHeader('http://cmd-it.dk/','authentification',$auth,false);
$client->__setSoapHeaders($header);
/* Requesting function list (interface) from SOAP server */
echo "<pre>";
var_dump($client->__getFunctions());
/* Executing a fuction, for example isAlive method */
$response = $client->__soapCall("isAlive", array("isAlive" => "true"));
var_dump($response);
/* Here a list of functions available on your server that we have requested by getFucntions() method */
/*
array(4) {
[0]=>
string(44) "isAliveResponse isAlive(isAlive $parameters)"
[1]=>
string(74) "createReservationResponse createReservation(createReservation $parameters)"
[2]=>
string(44) "isAliveResponse isAlive(isAlive $parameters)"
[3]=>
string(74) "createReservationResponse createReservation(createReservation $parameters)"
}
*/
在上面的示例中,我们将请求接口(getfunctions)并执行SOAP方法(__soapCall).
In the above example we will ask for interface (getfunctions) and execute a SOAP method (__soapCall).
致谢
这篇关于Soap身份验证标头和使用PHP的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!