使用基于表单的身份验证从网站读取 XML 文件
是否有一种标准方法可以从使用基于表单的身份验证的网站读取 XML 文件?我们想要将该文件读入桌面应用程序。
谢谢-戴夫
Is there a standard way to read an XML file from a website that uses forms based authentication? We want to read the file into a desktop app.
thanks - dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您正在谈论 ASP.NET 表单身份验证,这将是两个步骤过程:
以下是使用自定义的示例WebClient:
当然,在现实生活中情况可能是这样更复杂,因为根据站点的不同,您可能需要随请求一起发送 ViewState 和其他 ASP.NET 特定的废话。
If you are talking about ASP.NET Forms Authentication this will be a two step process:
Here's an example using a custom WebClient:
Of course in the real life things might be more complex because depending on the site you might need to send along ViewState and other ASP.NET specific crap along with the request.
在 http 请求中发布凭据,响应中将有一个身份验证 cookie,您必须在下一个请求中重用该身份验证 cookie
post the credentials in an http request, on the response there will be an authentication cookie that you have to reuse for your next requests
您将必须大致按照以下步骤使用 HTTPWebRequest/HTTPWebResponse:
1:使用请求向网站提交用户名和密码
2:保存cookies(我假设cookies将包含登录成功的信息)
3:使用另一个请求(包括这些 cookie)来获取 XML。
要查找初始请求的代码,您需要查看登录页面的源代码以查看提交操作,然后通过您的请求重现该代码。您也许可以使用 fiddler 或 firebug 等来帮助解决这个问题。
You're going to have to use HTTPWebRequest/HTTPWebResponse in roughly the following steps:
1: Use a request to submit the username and password to the website
2: Save the Cookies (I assume the cookies will contain the ok that the login worked)
3: Use another request, including these cookies, to get the XML.
To find the code that for the initial request you will need to look at the source code of the login page to see the submission action, and then reproduce this through your request. You may be able to use fiddler or firebug etc to help working this out.