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.

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

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备