【PHP开发】用curl向https发请求时的35号错误
放了个假发现以前写的程序的模拟登陆不管用了,中间输出,发现curl向https发请求时没有返回数据,输出错误信息,得到:
curl_errno($ch) -----> 35 curl_error($ch) -----> error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:reason(1112)
查了很多资料,终于发现要强行指定SSL的版本,即加上下面的话就可以了:
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
整个函数也贴下来供参考:
function sendPostHttps($url, $postData, $header=0, $referer=""){ $ch = curl_init () ; curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url) ; curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSLVERSION, 3); $result = curl_exec($ch); curl_close($ch); return $result; }