How can i Load a Xdocument online who needs a user

2019-08-25 15:45发布

Is it possible to Load an XML File who has a password and a username like so:

XDocument xmlDoc = XDocument.load("htt://myApp/MyTestFile", "Username", "passwordtest");

Please help, I am hanging on that last point for my app.

1条回答
成全新的幸福
2楼-- · 2019-08-25 16:22

How can i Load a Xdocument online who needs a username and a password

You could set the Credentials property of the XmlUrlResolver, as the document said :

Sets credentials used to authenticate web requests.

Then use XmlReader and XmlReaderSettings for the XDocument.

Something like this :

XmlUrlResolver res = new XmlUrlResolver();
res.Credentials = new NetworkCredential("username", "password");

XmlReaderSettings set = new XmlReaderSettings();
set.XmlResolver = res;

XDocument xmlDoc = XDocument.Load(XmlReader.Create("htt://myApp/MyTestFile", set));
查看更多
登录 后发表回答