php用curl实现https双向认证
$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; }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: php curl 模拟登陆https
- 下一篇: C++对ASCII文件的操作例子