php curl脚本来获取aspx页面的内容 [英] php curl script to get an aspx page's content

查看:174
本文介绍了php curl脚本来获取aspx页面的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经尝试了一天,现在得到一个xml feed到我的应用程序。通常不是一个问题,我有另外两个feed进入应用程序使用simpleXml方法,我在下面附加。



我的问题是,这个其他页面是一个aspx页面,似乎有某种重定向或可能只是使用一个使用干净的URL的aspx框架。 / p>

这是我用于其他两个数据拉取工作正常的脚本。

  $ grb_feed_url ='http://www.grb.uk.com/rss.php'; 
$ grb_jobs = simplexml_load_file($ grb_feed_url,'SimpleXMLElement',LIBXML_NOCDATA);

这是伟大的,但当我尝试的url http://www.milkround.com/rss.aspx 它不会返回任何内容。



然后我尝试了一个cURL脚本,这一个工作正常为godaddy示例,但没有返回Milkround url。也奇怪的是,如果我删除CURLOPT_FOLLOWLOCATION行或将其设置为0,它返回对象移动到这里。

  function get_data($ url)
{
$ ch = curl_init
$ timeout = 5;
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_CONNECTTIMEOUT,$ timeout);
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,1);
$ data = curl_exec($ ch);
curl_close($ ch);
return $ data;
}

$ returned_content = get_data('http://www.milkround.com/rss');
print_r($ returned_content);

/ *使用此脚本工作的URL示例* /
/ * $ returned_content = get_data('http://www.godaddy.com/hosting/website-builder.aspx '); * /

任何帮助将非常感激。



提前感谢。

解决方案

您需要在cURL请求中包含User-Agent标头, a 501错误:

  curl_setopt($ ch,CURLOPT_USERAGENT,Mozilla / 5.0(Windows; U; Windows NT 5.1; US; rv:1.8.1.1)Gecko / 20061204 Firefox / 4); 


Hi guys first ever forum post so shout if I havent worded this correctly.

I have been trying for about a day now to get an xml feed into my application. Not usually an issue and I have two other feeds coming into the application using the simpleXml method which I have attached below.

My issue is that this other page is an aspx page and it seems to have some sort of redirect or probably just using an aspx framework that is using a clean url.

This is the script I used for the other two data pulls that works fine.

$grb_feed_url = 'http://www.grb.uk.com/rss.php';
$grb_jobs = simplexml_load_file($grb_feed_url, 'SimpleXMLElement', LIBXML_NOCDATA);

That is great but when I try it for the url http://www.milkround.com/rss.aspx it returns nothing.

I then tried a cURL script, this one works fine for the godaddy example but return nothing for the Milkround url. Also strange is that if I remove the CURLOPT_FOLLOWLOCATION line or set it to 0 it returns with "object moved to here".

function get_data($url)
{
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

$returned_content = get_data('http://www.milkround.com/rss');
print_r($returned_content);

/* example of a url that works using this script */
/* $returned_content = get_data('http://www.godaddy.com/hosting/website-builder.aspx'); */

Any help would be really appreciated.

Thanks in advance.

解决方案

You need to include a User-Agent header in the cURL request, otherwise the site produces a 501 error:

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/4");

这篇关于php curl脚本来获取aspx页面的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆