且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

php soap 客户端,错误 wsdl 导致的错误?“未捕获的 SoapFault 异常:[HTTP] 无法连接到主机"

更新时间:2023-09-10 12:40:22

您想要做的是将您的代码包装在 try{}, catch{} 块中.例如,

What you want to do is wrap your code in a try{}, catch{} block. For example,

<?php
    try {
        ini_set('soap.wsdl_cache_enabled',0);
        ini_set('soap.wsdl_cache_ttl',0);

        $url = "https://test.mycustomer.com/api/TestService.asmx?wsdl";
        $client = new SoapClient($url, array("trace" => 1, "exception" => 0));

        $result = $client->GetMessage(NULL);

        echo "<pre>".print_r($result, true)."</pre>";
        if($result->GetMessageResult->Status == "Success")
        {
            echo "Item deleted!";
        }
    }
    catch (SoapFault $exception) {
        echo $exception->getMessage();
    }
?>

正如错误所说,Fatal error: Uncaught SoapFault exception: [HTTP] could not connect to host in ....,所以无论如何你都需要捕获异常.希望这会有所帮助.

As the error says, Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in ...., so you need to catch the exception in any case. Hope this helps.