使用HttpWebRequest在https上下文中加载http feed会触发400错误请求

时间:2012-06-11 20:48:32

标签: c# httpwebrequest

我正在运行以下代码来访问各种RSS http URL,但执行代码的我的Web应用程序是在https上。

HttpWebRequest request = 
   (HttpWebRequest)HttpWebRequest.Create(new Uri(blog["RSSURL"].ToString()));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ProhibitDtd = false;
XmlReader reader =  
   XmlReader.Create(response.GetResponseStream(), readerSettings);                        
SyndicationFeed feed = SyndicationFeed.Load(reader);

当我解雇时,我得到:

  

远程服务器返回错误:(400)错误请求    在System.Net.HttpWebRequest.GetResponse()

任何人都可以帮我弄清楚我是如何解决这个问题的吗?

1 个答案:

答案 0 :(得分:0)

您的示例网址适合我

string url = "http://blog.sharepointelearning.com/feed/";
XDocument xDoc = XDocument.Load(url);
var items = xDoc.Descendants("item")
        .Select(item => new 
        {
            Title = item.Element("title").Value,
            Link = item.Element("link").Value,
            Description = item.Element("description").Value,
        })
        .ToArray();