当尝试获取特定域的内容时,PHP Curl 不起作用

发布于 2024-12-07 00:25:40 字数 1115 浏览 0 评论 0原文

当尝试获取特定域的内容时,PHP Curl 不起作用。

特定的域是“www.net4winners.com.br”,它适用于每个域,但不适用于该域,它总是在curl输出中返回:“找不到对象”。

此测试的 PHP 代码:

<?php
function run_curl($url,$p=null)
    {
        $ch = curl_init();
        $options = array(
        CURLOPT_URL => $url,
        CURLOPT_HEADER => 0,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)",
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_FOLLOWLOCATION => 1
        );
        if($p != null)
        {
            $options[CURLOPT_CUSTOMREQUEST] = "POST";
            $options[CURLOPT_POST] = 1;
            $options[CURLOPT_POSTFIELDS] = $p;
        }

        curl_setopt_array($ch,$options);

        $resultado = curl_exec($ch);

        if($resultado) { return $resultado; } else { return curl_error($ch); }

        curl_close($ch);
    }
    $out = run_curl('http://www.net4winners.com.br/');
    echo $out;
?>

有人可以帮助我吗?

谢谢。

PHP Curl doesn't work when tried to get contents of a specific domain.

The specific domain is 'www.net4winners.com.br', it works with every domain but not with this domain, it always returns: 'object not found' in curl output.

PHP Code of this test:

<?php
function run_curl($url,$p=null)
    {
        $ch = curl_init();
        $options = array(
        CURLOPT_URL => $url,
        CURLOPT_HEADER => 0,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)",
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_FOLLOWLOCATION => 1
        );
        if($p != null)
        {
            $options[CURLOPT_CUSTOMREQUEST] = "POST";
            $options[CURLOPT_POST] = 1;
            $options[CURLOPT_POSTFIELDS] = $p;
        }

        curl_setopt_array($ch,$options);

        $resultado = curl_exec($ch);

        if($resultado) { return $resultado; } else { return curl_error($ch); }

        curl_close($ch);
    }
    $out = run_curl('http://www.net4winners.com.br/');
    echo $out;
?>

could someone help me please?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆追雨的时光 2024-12-14 00:25:40

它不起作用,因为服务器正在检查是否存在某些不是由 cURL 发送的标头。根据我的测试,您的案例中缺少的是Accept-Language。

尝试将以下内容添加到您的 $options 数组中:

CURLOPT_HTTPHEADER => array('Accept-Language: en-us')

示例:

<?php

$ch = curl_init('http://www.net4winners.com.br/');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept-Language: en-us'
));
curl_exec($ch);

It's not working because the server is checking for the existence of certain headers which are not sent by cURL. Based on my testing, the one that's missing in your case is Accept-Language.

Try adding the following to your $options array:

CURLOPT_HTTPHEADER => array('Accept-Language: en-us')

Example:

<?php

$ch = curl_init('http://www.net4winners.com.br/');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept-Language: en-us'
));
curl_exec($ch);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文