抱歉,想抓取的是这个rss:
http://www.achome.cn/blog/?feed=rss
使用simplexml_load_file
结果出错:
Warning: simplexml_load_file(http://www.achome.cn/blog/?feed=rss)
[function.simplexml-load-file]: failed to open stream: HTTP request failed!
HTTP/1.0 500 Internal Server Error in D:phpsitephprssfeedcheck.php on line 5
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning :
failed to load external entity “http://www.achome.cn/blog/?feed=rss”
in D:phpsitephprssfeedcheck.php on line 5
再使用file_get_contents与simplexml_load_string配合
Warning: file_get_contents(http://www.achome.cn/blog/?feed=rss) [function.file-get-contents]:
failed to open stream: HTTP request failed!
HTTP/1.0 500 Internal Server Error in D:phpsitephprssfeedcheck.php on line 3
用浏览器访问一切OK。
用.net中的HttpWebRequest
</pre>
static void Main(string[] args)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.achome.cn/blog/?feed=rss");
req.AllowAutoRedirect = true;
req.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
try
{
using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
{
using (StreamReader r = new StreamReader(res.GetResponseStream()))
{
Console.Write(r.ReadToEnd());
}
}
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
Console.Read();
}
与PHP中同样的错误,OMG
