当尝试获取特定域的内容时,PHP Curl 不起作用
当尝试获取特定域的内容时,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用,因为服务器正在检查是否存在某些不是由 cURL 发送的标头。根据我的测试,您的案例中缺少的是Accept-Language。
尝试将以下内容添加到您的
$options
数组中:示例:
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:Example: