<i id='1KFoz'><tr id='1KFoz'><dt id='1KFoz'><q id='1KFoz'><span id='1KFoz'><b id='1KFoz'><form id='1KFoz'><ins id='1KFoz'></ins><ul id='1KFoz'></ul><sub id='1KFoz'></sub></form><legend id='1KFoz'></legend><bdo id='1KFoz'><pre id='1KFoz'><center id='1KFoz'></center></pre></bdo></b><th id='1KFoz'></th></span></q></dt></tr></i><div id='1KFoz'><tfoot id='1KFoz'></tfoot><dl id='1KFoz'><fieldset id='1KFoz'></fieldset></dl></div>

      1. <tfoot id='1KFoz'></tfoot>
          <bdo id='1KFoz'></bdo><ul id='1KFoz'></ul>

        <small id='1KFoz'></small><noframes id='1KFoz'>

        <legend id='1KFoz'><style id='1KFoz'><dir id='1KFoz'><q id='1KFoz'></q></dir></style></legend>
      2. 无法理解 PHP 中的 SOAP

        时间:2023-05-22

        <small id='hI1NX'></small><noframes id='hI1NX'>

          <bdo id='hI1NX'></bdo><ul id='hI1NX'></ul>
          1. <i id='hI1NX'><tr id='hI1NX'><dt id='hI1NX'><q id='hI1NX'><span id='hI1NX'><b id='hI1NX'><form id='hI1NX'><ins id='hI1NX'></ins><ul id='hI1NX'></ul><sub id='hI1NX'></sub></form><legend id='hI1NX'></legend><bdo id='hI1NX'><pre id='hI1NX'><center id='hI1NX'></center></pre></bdo></b><th id='hI1NX'></th></span></q></dt></tr></i><div id='hI1NX'><tfoot id='hI1NX'></tfoot><dl id='hI1NX'><fieldset id='hI1NX'></fieldset></dl></div>

            <legend id='hI1NX'><style id='hI1NX'><dir id='hI1NX'><q id='hI1NX'></q></dir></style></legend>

              • <tfoot id='hI1NX'></tfoot>
                  <tbody id='hI1NX'></tbody>
                • 本文介绍了无法理解 PHP 中的 SOAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

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

                  这是我试过的代码:

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

                  ';var_dump($client->__getFunctions());回声'</pre><br/><br/><br/>';//由于上面的行返回函数我假设一切都很好,但直到这一点尝试{$client->__soapCall('HotelSearch',大批('ApiKey' =>'THE_API_KEY_GOES_HERE',//请注意,在实际代码中我将 API 密钥放在...'用户ID' =>session_id(),'用户代理' =>$_SERVER['HTTP_USER_AGENT'],'用户IP地址' =>$_SERVER['REMOTE_ADDR'],'酒店ID' =>'50563','签到' =>'07/02/2009','结帐' =>'07/03/2009','客人' =>'2','房间' =>'1','语言代码' =>'恩','显示货币' =>'美元','TimeOutInSeconds' =>'90'));}捕获(异常 $e){echo $e->getMessage();}

                  这会引发异常并回显以下内容:

                  服务器无法处理请求.--->你调用的对象是空的.

                  注意:我以前从未使用过 SOAP,所以我可能只是在做一些根本错误的事情,即使是让我朝着正确方向前进的小技巧也会非常感谢

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

                  试试{$client->__soapCall('HotelSearch',数组('请求' =>大批('ApiKey' =>'THE_API_KEY_GOES_HERE',//请注意,在实际代码中我将 API 密钥放在...'用户ID' =>session_id(),'用户代理' =>$_SERVER['HTTP_USER_AGENT'],'用户IP地址' =>$_SERVER['REMOTE_ADDR'],'酒店ID' =>'50563','签到' =>'2009-07-02','结帐' =>'2009-07-03','客人' =>2、'房间' =>1、'语言代码' =>'恩','显示货币' =>'美元','TimeOutInSeconds' =>90) ));}捕获(异常 $e){echo $e->getMessage();}

                  解决方案

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

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

                  $client->__soapCall('HotelSearch',大批(数组('请求' =>大批('ApiKey' =>'THE_API_KEY_GOES_HERE',//请注意,在实际代码中我将 API 密钥放在...'用户ID' =>session_id(),'用户代理' =>$_SERVER['HTTP_USER_AGENT'],'用户IP地址' =>$_SERVER['REMOTE_ADDR'],'酒店ID' =>'50563','签到' =>'07/02/2009','结帐' =>'07/03/2009','客人' =>'2','房间' =>'1','语言代码' =>'恩','显示货币' =>'美元','TimeOutInSeconds' =>'90'))));

                  Well here is the API I'm trying to use: http://www.hotelscombined.com/api/LiveRates.asmx?op=HotelSearch

                  Here is the code I've tried:

                  $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();
                  }
                  

                  Anywho this throws an exception and echos the following:

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

                  NOTE: I've never used SOAP before so it's possible I'm just doing something fundamentally wrong, even a small tip to get me in the right direction would be hugely appreciated

                  Tom Haigh suggested wrapping the values in another array which seems to be returning the same error message: (I always tried changing integers to be in integer form and the same with dates)

                  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();
                  }
                  

                  解决方案

                  I find when using PHP's SOAP implementation you end up wrapping everything up in more arrays than you think you need.

                  The below example seems to work, but also you need to format your date values correctly before it will work. I'm not sure of the best way of doing this - it might be that you can pass an Integer representing UNIX time and PHP will convert it for you.

                  $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 中的 SOAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP SoapClient 和复杂的标头 下一篇:将 PHP SoapClient 与本地 WSDL 文件(非 URI)一起使用的

                  相关文章

                  最新文章

                    <small id='mMMtC'></small><noframes id='mMMtC'>

                    <i id='mMMtC'><tr id='mMMtC'><dt id='mMMtC'><q id='mMMtC'><span id='mMMtC'><b id='mMMtC'><form id='mMMtC'><ins id='mMMtC'></ins><ul id='mMMtC'></ul><sub id='mMMtC'></sub></form><legend id='mMMtC'></legend><bdo id='mMMtC'><pre id='mMMtC'><center id='mMMtC'></center></pre></bdo></b><th id='mMMtC'></th></span></q></dt></tr></i><div id='mMMtC'><tfoot id='mMMtC'></tfoot><dl id='mMMtC'><fieldset id='mMMtC'></fieldset></dl></div>
                  1. <legend id='mMMtC'><style id='mMMtC'><dir id='mMMtC'><q id='mMMtC'></q></dir></style></legend>
                    • <bdo id='mMMtC'></bdo><ul id='mMMtC'></ul>
                    <tfoot id='mMMtC'></tfoot>