cURL:操作在0毫秒后超时

mad*_*bob 7 php curl

cURL给了我错误:

Operation timed out after 0 milliseconds with 0 out of 0 bytes received
Run Code Online (Sandbox Code Playgroud)

特别是,"0毫秒"部分是可疑的......

我的初始化代码:

$curl = curl_init($requestUrl); // private URL not published
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, 
  array("Content-Type: application/xml", "Accept: application/xml"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_HTTP200ALIASES, range(400, 599));
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
Run Code Online (Sandbox Code Playgroud)

超时似乎设置正确,可能与哪些相关?

小智 6

当尝试通过https连接时,我遇到了同样的问题.问题出在ssl版本上.这对我很有用:

$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
Run Code Online (Sandbox Code Playgroud)