2017-05-08 115 views
1

我試圖使用HTTPS鏈接發出soap請求。 我得到捲曲失敗:0(這意味着沒有錯誤)但是,我收到一個空字符串。使用Curl的HTTPS請求失敗:0但Curl中沒有響應PHP

$url = $soapUrl; 

$soap_do = curl_init(); 
set_time_limit(0); 
curl_setopt($soap_do, CURLOPT_URL,   $url); 
curl_setopt($soap_do, CURLOPT_AUTOREFERER, true); 
curl_setopt($soap_do, CURLOPT_MAXREDIRS,  10); 
curl_setopt($soap_do, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($soap_do, CURLOPT_POST,   true); 
curl_setopt($soap_do, CURLOPT_POSTFIELDS,  $xml_post_string); 
curl_setopt($soap_do, CURLOPT_VERBOSE,  TRUE); 
curl_setopt($soap_do, CURLOPT_HTTPHEADER,  $headers); 

$response = curl_exec($soap_do); 
$error = curl_error($soap_do); 

var_dump($response); 

echo "Curl Failed: " . curl_errno($soap_do), "<br/>"; 
echo curl_error($soap_do); 

我的代碼有問題嗎?

+0

使用'curl_getinfo()'查看關於請求結果的更多細節。 –

+0

您缺少''output = curl_exec($ soap_do);' – Hackerman

+0

我更新了我的代碼請chewck – phpmeter

回答

0

您的curl_exec();在哪裏?

您正在設置很多選項,但我認爲最多的選項僅用於微調。 你可以用這個例子,我在另一個答案給了嘗試:

Send an XML post request to a web server with CURL

編輯: PHP也有一個SOAP客戶端打造,也許你可以試試看:

$context = stream_context_create([ 
     'http' => [ 
      'user_agent' => 'PHPSoapClient' 
     ], 
     'ssl' => [ 
      'verify_peer' => false, 
      'verify_peer_name' => false, 
      'allow_self_signed' => true 
     ] 
    ]); 

    $soap = new SoapClient($url, [ 
     'stream_context' => $context, 
     'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY 
     'trace' => 1, 
     'exception' => 1, 
     'keep_alive' => false, 
     'connection_timeout' => 500000 
    ]); 

    // Then call the SOAP method 
    echo $soap->version(); 
+0

我更新了我的代碼,請檢查] – phpmeter

+0

您的更新代碼適合我。也許你應該設置'CURLOPT_SSL_VERIFYPEER false'或者嘗試在SoapClient中構建。查看我的更新回答 – PKeidel

+0

我需要證書才能訪問https鏈接嗎? – phpmeter