dpizd08264 2014-02-08 14:46
浏览 82
已采纳

PHP SoapClient __getLastRequest和__getLastRequestHeaders为成功调用返回NULL

I'm going through tutorials on webservices and SOAP. In learning about these, I created a php file to act on the WSDL provided by w3schools that converts temperatures between Celsius and Fahrenheit.

I wrote the following PHP code which fires successfully:

$wsdl = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
$soapClient = new SoapClient($wsdl);

// print_r ($soapClient->__getFunctions());
// print_r ($soapClient->__getTypes());

$parameters = array("Celsius" => "0");

$result = $soapClient->__soapCall("CelsiusToFahrenheit", array($parameters) );


echo "key: " . key($result) . "<br />" ;
echo "value: " . current($result) . "<br />" ;

The browser successfully returns the following:

key: CelsiusToFahrenheitResult
value: 32

I then tried to use the SoapClient methods __getLastRequest() and __getLastRequestHeaders() to take a look at the headers that were sent and see how they compare to what I had been reading and both method calls returned null

echo "Last call headers: <br />";
echo $soapClient->__getLastRequestHeaders();
echo "<br />" ;
echo "Last call headers: <br />";
echo $soapClient->__getLastRequest();

I reviewed the notes and example in the php manual for _getLastRequestHeaders() and it looks like everything is set up correctly. I can't tell what I'm doing wrong :/

Any help would be appreciated!

  • 写回答

1条回答 默认 最新

  • dqq9695 2014-02-08 14:51
    关注

    If you don't set trace to true in the options argument of the constructor of the SoapClient, it won't store these. So simply put, this will work for you:

    $soapClient = new SoapClient($wsdl, array('trace' => true));
    

    ... which the manual page you linked to explicitly states:

    Note:

    This function only works if the SoapClient object was created with the trace option set to TRUE.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多