开发者

System.ServiceModel.Syndication authentication

开发者 https://www.devze.com 2022-12-21 01:10 出处:网络
How can I use authentication with System.ServiceModel.Syndication to read a private RSS? The code I use right now just returns forbidden.

How can I use authentication with System.ServiceModel.Syndication to read a private RSS?

The code I use right now just returns forbidden.

I have tried adding &PASS=password and &PASSWORD=password to the URL but it doesnt help.

    try
    {
        using (XmlReader reader = XmlReade开发者_运维问答r.Create("http://trac:8080/Project/report/7?format=rss&USER=enr"))
        {
            tracFeed = SyndicationFeed.Load(reader);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }


Have you tried creating a WebRequest for your URI, passing Credentials to the webrequest. Then you could simply create an XmlReader from the response stream of the request, and load that reader via SyndicationFeed.Load, afaik Load itself provides no direct way of passing credentials, you will need to issue a web request and attach basic credentials to the URI you are requesting. This article is trying to do something similar to your issue.


@bnkdev You are right, but something doesnt work I dont know why but it seems to be a problem on the server I guess?

    SyndicationFeed tracFeed;

    string user = "enr";
    string password = "enr";

    System.Net.WebClient wc = new System.Net.WebClient();

    wc.Credentials = new System.Net.NetworkCredential(user, password);

    //this works!
    string web = wc.DownloadString("http://trac:8080/project/login/xmlrpc");

    //this gives a 403 forbidden !! :-(
    System.IO.Stream webClientStream = wc.OpenRead("http://trac:8080/project/report/7?format=rss&USER=enr");

    try
    {

        using (XmlReader reader = XmlReader.Create(webClientStream))
        {
            tracFeed = SyndicationFeed.Load(reader);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        webClientStream.Close();
    }

Both urls work in IE, the difference is the first one immediately pops up a login window, but the second one redirects me to a page where I can log in...

So I do think something is fishy there....

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号