使用php版本5.3.2和curl版本7.19.7时,我在连接到https url时遇到问题。它只是一小段代码,但这里是我的PHP代码的更新版本
$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>';
返回给我
如果我在同一位置使用exec方法
$url = "https://lms.lifeline.nl/mailwebservice/inline";
exec("curl $url", $output, $status);
print_r($output);
我得到一个像这样的结果,它永远不会到达回声“test2”;死;我的代码的一部分
这是我在evry 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 :(得分: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>';
答案 1 :(得分: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);