HttpRequest:通过AuthLogin
我需要制作一个简单的程序,使用给定的凭据记录到某个网站,然后导航到某个元素(链接)。 甚至有可能(我的意思是这个 Authlogin 的事情)?
编辑:抱歉 - 我在公司机器上,无法单击“投票”或“添加评论” - 页面显示“已完成,但页面上有错误”(即..)。我非常感谢您的回答和评论,您对我帮助很大!
I would need to make a simple program that logs with given credentials to certain website and then navigate to some element (link).
It is even possible (I mean this Authlogin thing)?
EDIT: SORRY - I am on my company machine and I cannot click on "Vote" or "Add comment" - the page says "Done, but with errors on page" (IE..). I do appreciate your answers and comments, you have helped me a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
主要要做的事情是:
假设我们'就普通的 Web 表单而言,您可能需要将
CookieContainer
与您的WebRequest
一起使用,以便接受来自登录请求的 cookie,然后重新提供发送后续请求时使用它们(这样的上下文不会由HttpWebRequest
自动维护):-Main things to do are:
Assuming we're talking a normal web form you'll probably need to use a
CookieContainer
with yourWebRequest
s in order to accept the cookies that come from the login request and then re-supply them when sending subsequent requests (such context is not automagically maintained byHttpWebRequest
) :-是的。这是可能的。
请参阅以下代码:
yes. it is possible.
see following code:
这部分取决于登录过程的管理方式。这实际上是通过网络表单完成的吗?如果是这样,您需要像普通浏览器一样发布表单。
如果是通过 HTTP 身份验证完成的,您应该能够在 Web 请求中设置凭据,告诉它进行预身份验证,一切都会顺利。
It will partly depend on how the login process is managed. Is this actually done via a web form? If so, you'll need to post the form, just as a normal browser would.
If it's done over HTTP authentication, you should be able to set the credentials in the web request, tell it to pre-authenticate, and all should be well.