2017-06-29 171 views
1

我在使用php版本5.3.2和curl版本7.19.7時連接到https url時出現問題。它的一個非常小的一段代碼,但這裏是我的PHP代碼cURL https連接

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 

    /* prepare a stream for writing verbose data to */ 
    $vbh = fopen('php://temp', 'w+'); 


    curl_setopt($ch, CURLOPT_CAINFO, $certificate); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
    curl_setopt($ch, CURLOPT_SSLVERSION, 6); 

    /* verbose logging */ 
    curl_setopt($ch, CURLOPT_VERBOSE, true); 
    curl_setopt($ch, CURLOPT_NOPROGRESS, true); 
    curl_setopt($ch, CURLOPT_STDERR, $vbh); 


    curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
    curl_setopt($ch, CURLOPT_USERPWD, $credentials); 


    $res=(object)array(
     'response' => curl_exec($ch), 
     'info'  => (object)curl_getinfo($ch), 
     'errors' => curl_error($ch) 
    ); 
    echo 'test2'; die; 
    curl_close($ch); 

    rewind($vbh); 
    $res->debug=stream_get_contents($vbh); 
    fclose($vbh); 

    echo '<pre>',print_r($res,true),'</pre>'; 

的updatet版本返回我這個頁面enter image description here

怎麼過,如果我使用exec梅索德的同一位置上這樣

$url = "https://lms.lifeline.nl/mailwebservice/inline"; 
    exec("curl $url", $output, $status); 
    print_r($output); 

我得到的結果是這樣的enter image description here它永遠不會到達echo'test2';死;我的代碼部分

這裏是我艾薇VAR使用數據:

$data ='<?xml version="1.0" encoding="utf-8"?> 
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mail="http://www.enovation.nl/ems/mailwebservice"> 
    <soapenv:Header/> 
    <soapenv:Body> 
    <mail:ListRequest> 
     <mail:accountId>***********</mail:accountId> 
    </mail:ListRequest> 
    </soapenv:Body> 
</soapenv:Envelope>'; 

     $url = 'https://lms.lifeline.nl/mailwebservice/inline/'; 

     $certificate = "full path to crt file"; 

     $headers = array( 
      'Content-Type: text/xml; charset="utf-8"', 
      'Content-Length: '.strlen($data), 
      'Accept: text/xml', 
      'Cache-Control: no-cache', 
      'Pragma: no-cache', 
      'SOAPAction: "Send"' 
     ); 

     $credentials = "$username:$password"; 

我想不通,爲什麼在第1節我不能得到響應和它殺死我的代碼,爲什麼在第2節我確實得到了答覆。

也似乎我的cURL循環試圖連接到該網址。

+0

是整個捲曲代碼?上面給出的網址立即提示授權,所以你的代碼需要考慮http認證,很可能使用SSL證書,驗證服務器等,並遵循重定向 – RamRaider

+0

以及這是不是我的完整版本這是https://codeshare.io/ayD110,但因爲curl_exec休息我不能使用curl_error來檢查什麼是錯的惠特請求 – EndLessWave

回答

0

你可以試試這個禁用SSL驗證

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://lms.lifeline.nl/mailwebservice/inline/'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_exec($ch); 
+0

同樣的問題,我仍然得到連接被重置頁面 – EndLessWave

+0

你使用代理嗎? –

+0

不,這是不是這種情況然而,當我運行這個cURL在我的本地工作站使用usbwebserver而不是在服務器上,我得到了迴應 – EndLessWave

1

,如果你要嘗試推行一些/所有這一切你可能會得到更多的信息:

/* details copied from externally linked file */ 

$credentials = "username:password"; 

$body='oapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mail="http://www.enovation.nl/ems/mailwebservice"> 
    <soapenv:Header/> 
    <soapenv:Body> 
    <mail:ListRequest> 
     <mail:accountId>**********</mail:accountId> 
    </mail:ListRequest> 
    </soapenv:Body> 
</soapenv:Envelope>'; 

SOAP主體應該,我認爲,看起來更像這樣:

$body='<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mail="http://www.enovation.nl/ems/mailwebservice"> 
    <soap:Header/> 
    <soap:Body> 
    <mail:ListRequest> 
     <mail:accountId>3456845125</mail:accountId> 
    </mail:ListRequest> 
    </soap:Body> 
</soap:Envelope>'; 


$headers = array( 
    'Content-Type: text/xml; charset="utf-8"', 
    'Content-Length: '.strlen($body), 
    'Accept: text/xml', 
    'Cache-Control: no-cache', 
    'Pragma: no-cache', 
    'SOAPAction: "Send"' 
); 



$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 

/* prepare a stream for writing verbose data to */ 
$vbh = fopen('php://temp', 'w+'); 


curl_setopt($ch, CURLOPT_CAINFO, $certificate); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($ch, CURLOPT_SSLVERSION, 6); 

/* verbose logging */ 
curl_setopt($ch, CURLOPT_VERBOSE, true); 
curl_setopt($ch, CURLOPT_NOPROGRESS, true); 
curl_setopt($ch, CURLOPT_STDERR, $vbh); 


curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $body); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_USERPWD, $credentials); 

$res=(object)array(
    'response' => curl_exec($ch), 
    'info'  => (object)curl_getinfo($ch), 
    'errors' => curl_error($ch) 
); 
curl_close($ch); 

rewind($vbh); 
$res->debug=stream_get_contents($vbh); 
fclose($vbh); 

echo '<pre>',print_r($res,true),'</pre>'; 
+0

這給了我更多的信息,當我可以得到連接startet肯定,但它運行到同樣的問題,即在提交響應=> curl_exec($ ch)時,代碼停止工作並彈出相同的錯誤頁面 – EndLessWave

+1

您確定提供了所有正確的細節 - 我們不知道您在某些方面提供了什麼這些變量,比如'$ credentials','$ headers'或'$ body',這並不能真正幫助解決難題。我很欣賞用戶名/密碼的詳細信息不會被共享,但變量的編輯版本可能會有所幫助 - 以及您實際使用的完整代碼 – RamRaider

+0

oow我是sory這些變量設置高於我在此共享的鏈接curl var中的所有內容都是未知的https://codeshare.io/GqNwnx – EndLessWave