CURL执行返回空响应并显示

AnN*_*LaI 7 php curl

我在我的项目中使用CURL,它在本地工作正常但如果我使用相同的代码它没有执行,我试图调试它.输出如下:

Took 0 seconds to send a request to https://www.google.co.in
Run Code Online (Sandbox Code Playgroud)

我使用了以下示例代码:

$handle=curl_init('https://www.google.co.in');
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($handle);

if(!curl_errno($handle))
{
    $info = curl_getinfo($handle);

    echo '<br/> Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}
else
{
    echo 'Curl error: ' . curl_error($handle);
}

echo $content;
Run Code Online (Sandbox Code Playgroud)

问题在服务器中,我不知道在php.ini中启用什么.

请注意,在服务器中,CURL和SSL已启用.如果有人遇到类似的问题,请分享解决方案.

icc*_*c97 9

在这种情况下对我来说,问题是我得到了302重定向而不是实际的get请求.

开机后CURLOPT_VERBOSE从这个答案

$fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fp);
Run Code Online (Sandbox Code Playgroud)

我得到以下内容errorlog.txt:

* Connected to www.example.com (X.X.X.X) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSL connection using ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
*        subject: OU=Domain Control Validated; OU=COMODO SSL; CN=www.example.com
*        start date: 2016-04-28 00:00:00 GMT
*        expire date: 2018-04-08 23:59:59 GMT
*        issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
*        SSL certificate verify ok.
> GET /path/to/file.php
HTTP/1.1^M
Host: www.example.com^M
Accept: */*^M
^M
< HTTP/1.1 302 Found^M
* Server nginx is not blacklisted
< Server: nginx^M
< Date: Tue, 20 Sep 2016 02:06:45 GMT^M
< Content-Type: text/html^M
< Transfer-Encoding: chunked^M
< Connection: keep-alive^M
< X-Powered-By: PHP/5.5.9-1ubuntu4.19^M
< Location: https://www.example.com/other/url/^M
< ^M
* Connection #0 to host www.example.com left intact
Run Code Online (Sandbox Code Playgroud)

NB

  1. HTTP/1.1 302 Found (应该是200响应)
  2. Location: https://www.example.com/other/url/GET请求URL 不同


Jer*_*der 4

\n

问题:

\n

功能curl_exec被禁用。该怎么办?

\n

解决方案:

\n

为了消除此错误消息,您需要执行以下操作之一

\n
    \n
  1. curl_exec从文件disable_functions中删除字符串php.ini
  2. \n
  3. 如果您没有\xe2\x80\x99t 访问该php.ini文件的权限,请要求您的托管提供商删除上面的字符串
  4. \n
  5. 将托管提供商更改为允许运行该curl_exec功能的托管提供商。
  6. \n
\n

这是 中的条目示例php.ini

\n

更改自:

\n

disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,show_source,eval,posix_getpwuid

\n

到:

\n

disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,show_source,eval,posix_getpwuid

\n
\n

资料来源:http://tipstricks.itmatrix.eu/ ?p=1365

\n