大家好,有人可以帮助我吗,这是一段简单的代码:
try {
$ch = curl_init();
if ($ch === false) {
throw new Exception('failed to initialize');
}
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US)
AppleWebKit/532.4 (KHTML, like Gecko)
Chrome/4.0.233.0 Safari/532.4";
$referer = "http://www.google.com/";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$result = curl_exec($ch);
if ($result === false) {
throw new Exception(curl_error($ch), curl_errno($ch));
}
curl_close($ch);
} catch(Exception $e) {
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
curl_exec() 总是返回 false。我使用curl_error()检查了错误,(OpenSSL SSL_read:连接已重置)
您必须添加下一个:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);