如何使用 XmlTextReader 从 https 加载 xml
我正在使用 System.Xml.XmlTextReader 从 http 位置读取 xml 流。现在我需要支持才能从安全的 https 站点读取内容。如何通过以某种方式提供用户凭据来做到这一点?
I am using System.Xml.XmlTextReader
to read xml stream from a http location. Now I need support to read from a secure https site. How can I do this by providing user credentials in some way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 MSDN 上的文档,了解 HttpWebRequest.Credentials< /a> 属性。它包含使用 CredentialCache 的示例。
这可能是您所需要的(在集成安全方案中),但您可能需要阅读 NetworkCredential 文档,如果您想以字符串形式提供用户名和密码。
一旦 HttpWebRequest 开始工作,你只需说:
Check out the documentation at MSDN for the HttpWebRequest.Credentials property. It contains a sample using the CredentialCache.
This may be what you need (in a integrated security scenario), but you might want to read the docs of NetworkCredential as well if you want to provide a username and password as strings.
Once you have the HttpWebRequest working you just say:
您是否已经拥有使用
WebClient
或HttpWebRequest
的相关代码?这将是我的起点 - 确保您可以正确下载数据,然后将响应流传递到XmlReader.Create(Stream)
。您应该能够在不解析 XML 的情况下测试 Web 部分 - 只需打印出下载的数据以确保其看起来正确。
Do you already have the relevant code to use
WebClient
orHttpWebRequest
? That would be my starting point - make sure you can download the data appropriately, then just pass the response stream intoXmlReader.Create(Stream)
.You should be able to test the web part of things without parsing the XML - just print out the downloaded data to make sure it looks correct.