2012-12-25 89 views
34

我需要調試使用soap客戶端的代碼。我發現php.net getLast *方法,但是當我試圖獲得最後的要求進行調試,它返回NULL如何轉儲SoapClient調試請求?

<?php 

    $client = new SoapClient("http://www.webservicex.net/ConverPower.asmx?WSDL"); 

    $response = $client->ChangePowerUnit(array(
     "PowerValue" => 100, 
     "fromPowerUnit" => "horsepower", 
     "toPowerUnit" => "megawatts" 
    )); 


    echo "====== REQUEST HEADERS =====" . PHP_EOL; 
    var_dump($client->__getLastRequestHeaders()); 
    echo "========= REQUEST ==========" . PHP_EOL; 
    var_dump($client->__getLastRequest()); 
    echo "========= RESPONSE =========" . PHP_EOL; 
    var_dump($response); 

?> 

代碼執行的結果:

$php soap_test.php 

====== REQUEST HEADERS ===== 
NULL 
========= REQUEST ========== 
NULL 
========= RESPONSE ========= 
object(stdClass)#2 (1) { 
    ["ChangePowerUnitResult"]=> 
    float(0.0746) 
} 

如何得到身體的內容和最後的SoapClient請求的標題?如果SoapClient的創建對象設置爲TRUE跟蹤選項

回答

43

These functions纔有效。

嘗試:

$client = new SoapClient("http://www.webservicex.net/ConverPower.asmx?WSDL", array('trace' => 1)); 
+2

即使@xdazz是正確的,我強烈建議還加上'''「例外」 => 0'''在SoapClient的方法的參數,這樣你就可以查看您的通話即使你收到了錯誤的迴應,也會做出決定。 – Dragon54