php - cURL:操作在 0 毫秒后超时

标签 php curl

cURL 给我错误:

Operation timed out after 0 milliseconds with 0 out of 0 bytes received

特别是“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);

超时似乎设置正确,可能与什么有关?

最佳答案

我在尝试通过 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);

关于php - cURL:操作在 0 毫秒后超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22485811/

相关文章:

php - 您当前的 session 已过期。 Magento2

php - 删除句子中的所有空格和逗号

php - 通过 Cloudfront 上传到 S3

php - 如何使用表单在 symfony 2 中编辑用户权限?

curl - 如何在 postman 中传递客户端凭据?

curl - 如何使用 wget/curl 下载给定网页上 .zip 文件的所有链接?

php - 循环生成从今天开始的最后十个星期一

perl - Mailchimp v3.0 API,使用 Perl Curl

linux - 使用 Bash 来 cURL 网站并使用 grep 查找关键字

facebook - 使用 curl 将 base64 编码的图像作为表单变量发送