2017-06-29 105 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