gpt4 book ai didi

php - 无法理解 PHP 中的 SOAP

转载 作者:可可西里 更新时间:2023-11-01 00:53:54 25 4
gpt4 key购买 nike

这是我正在尝试使用的 API:http://www.hotelscombined.com/api/LiveRates.asmx?op=HotelSearch

这是我试过的代码:

$client = new SoapClient('http://www.hotelscombined.com/api/LiveRates.asmx?WSDL');

echo '<pre>'; var_dump($client->__getFunctions()); echo '</pre><br /><br /><br />';
//since the above line returns the functions I am assuming everything is fine but until this point

try
{
$client->__soapCall('HotelSearch',
array(
'ApiKey' => 'THE_API_KEY_GOES_HERE', // note that in the actual code I put the API key in...
'UserID' => session_id(),
'UserAgent' => $_SERVER['HTTP_USER_AGENT'],
'UserIPAddress' => $_SERVER['REMOTE_ADDR'],
'HotelID' => '50563',
'Checkin' => '07/02/2009',
'Checkout' => '07/03/2009',
'Guests' => '2',
'Rooms' => '1',
'LanguageCode' => 'en',
'DisplayCurrency' => 'usd',
'TimeOutInSeconds' => '90'
)
);
}
catch (Exception $e)
{
echo $e->getMessage();
}

任何抛出异常并回显以下内容的人:

Server was unable to process request. ---> Object reference not set to an instance of an object.

注意:我以前从未使用过 SOAP,所以我可能只是在做一些根本性的错误,即使是一个能让我朝着正确方向前进的小提示,我们也将不胜感激

Tom Haigh 建议将值包装在另一个似乎返回相同错误消息的数组中:(我总是尝试将整数更改为整数形式并且与日期相同)

try
{
$client->__soapCall('HotelSearch',
array('request' =>
array(
'ApiKey' => 'THE_API_KEY_GOES_HERE', // note that in the actual code I put the API key in...
'UserID' => session_id(),
'UserAgent' => $_SERVER['HTTP_USER_AGENT'],
'UserIPAddress' => $_SERVER['REMOTE_ADDR'],
'HotelID' => '50563',
'Checkin' => '2009-07-02',
'Checkout' => '2009-07-03',
'Guests' => 2,
'Rooms' => 1,
'LanguageCode' => 'en',
'DisplayCurrency' => 'usd',
'TimeOutInSeconds' => 90
) )
);
}
catch (Exception $e)
{
echo $e->getMessage();
}

最佳答案

我发现在使用 PHP 的 SOAP 实现时,您最终会将所有内容包装在比您认为需要的更多的数组中。

下面的示例似乎可以工作,但您还需要正确设置日期值的格式才能工作。我不确定这样做的最佳方法 - 可能是您可以传递一个代表 UNIX 时间的整数,PHP 会为您转换它。

$client->__soapCall('HotelSearch', 
array(
array('request' =>
array(
'ApiKey' => 'THE_API_KEY_GOES_HERE', // note that in the actual code I put the API key in...
'UserID' => session_id(),
'UserAgent' => $_SERVER['HTTP_USER_AGENT'],
'UserIPAddress' => $_SERVER['REMOTE_ADDR'],
'HotelID' => '50563',
'Checkin' => '07/02/2009',
'Checkout' => '07/03/2009',
'Guests' => '2',
'Rooms' => '1',
'LanguageCode' => 'en',
'DisplayCurrency' => 'usd',
'TimeOutInSeconds' => '90'
)
)
)
);

关于php - 无法理解 PHP 中的 SOAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1027745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com