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

末鹿安然 提交于 2020-01-06 06:52:40

问题


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:


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));


来源:https://stackoverflow.com/questions/47884894/how-can-i-load-a-xdocument-online-who-needs-a-username-and-a-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!