Making SOAP-call in PHP and setting SSL version

后端 未结 6 2058
慢半拍i
慢半拍i 2021-02-07 16:31

I\'ve made several scripts working with external WSDL. I have encountered one I have to integrate into our system that I can\'t get to work. I\'be been trying for a week without

6条回答
  •  野性不改
    2021-02-07 16:52

    I had the same problem, the following wrapper solved it (i had to force SSL2)

    class StupidWrapperForOracleServer extends SoapClient {
      protected function callCurl($url, $data, $action) {
         $handle   = curl_init();
         curl_setopt($handle, CURLOPT_URL, $url);
         curl_setopt($handle, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml", 'SOAPAction: "' . $action . '"'));
         curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
         curl_setopt($handle, CURLOPT_SSLVERSION, 2);
         $response = curl_exec($handle);
         if (empty($response)) {
           throw new SoapFault('CURL error: '.curl_error($handle),curl_errno($handle));
         }
         curl_close($handle);
         return $response;
       }
    
       public function __doRequest($request,$location,$action,$version,$one_way = 0) {
           return $this->callCurl($location, $request, $action);
       }
     }
    

    Btw. if it fails at the downloading the WSDL file part, then download the WSDL manually (with curl for example), and use that file locally. IMHO __doRequest is not called while in the WSDL downloading stage.

    file_put_contents(dirname(__FILE__) .'/Server.wsdl',get_wsdl()); //get_wsdl uses the same wrapper as above
    $oWS = new StupidWrapperForOracleServer(dirname(__FILE__) .'/Server.wsdl',array('trace'=>1,'cache_wsdl'=>0));
    

提交回复
热议问题