使用 PHP SoapClient 連 HTTPS 的 WebService 遇到的錯誤,先記錄下來
需要的 PHP Module
soap、openssl
一般連結方式
錯誤訊息:[error] PHP Fatal error: SoapClient::SoapClient() [function.SoapClient-SoapClient]:’location’ and ‘uri’ options are required in nonWSDL mode
1 2 |
$url = "https://SomeWebService.asmx?wsdl"; $oSoapClient = new SoapClient ( $url ); |
正確的參數
1 2 3 4 5 6 7 8 |
// options for ssl in php 5.6.5 $url = "https://SomeWebService.asmx?wsdl"; $opts = array( 'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false) ); // SOAP 1.2 client $params = array ('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => SOAP_1_2, 'trace' => 1, 'exceptions' => 1, "connection_timeout" => 180, 'stream_context' => stream_context_create($opts) ); $oSoapClient = new SoapClient ( $url . "?WSDL", $params ); |