牛骨文教育服务平台(让学习变的简单)
博文笔记

php用curl实现https双向认证

创建时间:2012-12-19 投稿人: 浏览次数:3241
$strurl="https://192.168.6.120/index.html";
function gethttpsdata($strurl){
	$tuCurl = curl_init(); 
	curl_setopt($tuCurl, CURLOPT_URL, $strurl); 
	curl_setopt($tuCurl, CURLOPT_PORT , 443); 
	curl_setopt($tuCurl, CURLOPT_VERBOSE, 0); 
	curl_setopt($tuCurl, CURLOPT_HEADER, 0); 
	curl_setopt($tuCurl, CURLOPT_SSLVERSION, 3); 
	
	curl_setopt($tuCurl, CURLOPT_SSLCERT, getcwd()."/newcert.pem"); 
	curl_setopt($tuCurl, CURLOPT_SSLCERTPASSWD,"xiaozl");
	curl_setopt($tuCurl, CURLOPT_SSLCERTTYPE,"PEM");
	
	curl_setopt($tuCurl, CURLOPT_SSLKEY, getcwd()."/newkey.pem"); 
	curl_setopt($tuCurl, CURLOPT_SSLKEYPASSWD,"xiaozl");
	curl_setopt($tuCurl, CURLOPT_SSLKEYTYPE,"PEM"); 
	
	curl_setopt($tuCurl, CURLOPT_CAINFO, getcwd()."/cacert.pem"); 
	 
	curl_setopt($tuCurl, CURLOPT_POST, 1); 
	curl_setopt($tuCurl, CURLOPT_SSL_VERIFYPEER, 1); 
	curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1); 
	
	//curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $data); 
	//curl_setopt($tuCurl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: "/soap/action/query"", "Content-length: ".strlen($data))); 
	
	$tuData = curl_exec($tuCurl); 
	if(!curl_errno($tuCurl)){ 
	  $info = curl_getinfo($tuCurl); 
	 // echo "Took " . $info["total_time"] . " seconds to send a request to " . $info["url"]; 
	} else { 
	  echo "Curl error: " . curl_error($tuCurl); 
	} 
	curl_close($tuCurl); 
	echo $tuData; 
}

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。