使用C#登录网页 [英] Login to web page using C#

查看:541
本文介绍了使用C#登录网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想登录到一定网页和下载几页登录的用户。我想我从理论上知道该怎么办的基础上,回答这个计算器问题,但我不知道,这里的地址我应该把登录凭据。在上面的问题,这是很明显,但它不是那么明显在Aukro

我会为任何avice ......非常感谢。)


< DIV CLASS =h2_lin>解决方案

一个棘手的问题是,这个登录页面设置为数众多的会话cookie,并追加了一些独特的查询字符串参数为您的会话的事实。 。据推测,你需要从服务器为您创建的每个session中获取良好的价值观



在你的土地上的 https://ssl.aukro.cz/enter%5Flogin.php ,你会得到一个302发现(这实际上是用于重定向)。完整的请求是这样的:

 
日期星期三,26八月2009 GMT十七点50分05秒
服务器Apache的
因人而异接受编码
的Set-Cookie WS2 = acda7c76687f;到期=周三,26月 - 2009年十八时20分05秒格林尼治标准时间;路径= /;域= .aukro.cz
过期星期四,1981年11月19日8时52分零零秒GMT
缓冲控制无店面,无缓存,必重新验证,后检查= 0,前检查= 0
语用无缓存
位置https://ssl.aukro.cz/enter_login.php?session=NmQ2YQFRBVABVgFRVFQAXVRXVFZXWlcHBVRVWAcGUF0OUVJWVVRRXFVUBFFTAAcGAFxUA1NSY2JkZQ%3D%3D&global_login_hash=e16bd60f566a0ae3752997bf21844c4ec2bd0d22&session_login_hash=fecd7825582b6d038d288f67c368090aa369c85d&url=OTFhY1hFRkYDHk4UR0YcV0xaEwweUkgZXEMTDEIeU1VaVBIQb1RARFZDTxNYQQ1YVm4FCkIMAzAxMjY%3D
内容 - 编码gzip的
的Content-Length 26
保持活动超时= 2,最大值= 9999
连接保持
内容类型text / html;字符集= UTF-8

您将需要抓住的URL位置,并将它设置(WS2),该cookie。然后,你需要拖放到你抓着的重定向URL,并得到它集饼干,这是其余 WS2 stsd_refr qeppo_login



您则需要填写在POST身体的表单元素如上所述,在你们提供的链接中提到。



不知道这个网站你想登录到任何东西,我斗胆,如果你不猜吨得到良好的会话变量,饼干,包括他们为每个逻辑请求,您的登录尝试可能会失败的。



长话短说,只是使用Fiddler或Firebug的捕捉到了什么登录会话的样子,并使用你已经看到了技术模仿它。


I would like to login to a certain web page, and download few pages as logged in user. I think I theoretically know what to do, based on an answer to this stackoverflow question, but I have no idea, where in the address should I put the login credentials. In the question above, it is quite obvious, but it is not so obvious at Aukro.
I'd be very grateful for any avice... :)

解决方案

One tricky part is the fact that this login page sets a bunch of session cookies and appends some unique query string parameters for your session. Presumably, you'll need to retrieve good values from the server for each session you create.

When you land on https://ssl.aukro.cz/enter%5Flogin.php, you get a 302 Found (which in practice is used for redirects). The full request looks like this:

Date    Wed, 26 Aug 2009 17:50:05 GMT
Server  Apache
Vary    Accept-Encoding
Set-Cookie  ws2=acda7c76687f; expires=Wed, 26-Aug-2009 18:20:05 GMT; path=/; domain=.aukro.cz
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma  no-cache
Location    https://ssl.aukro.cz/enter_login.php?session=NmQ2YQFRBVABVgFRVFQAXVRXVFZXWlcHBVRVWAcGUF0OUVJWVVRRXFVUBFFTAAcGAFxUA1NSY2JkZQ%3D%3D&global_login_hash=e16bd60f566a0ae3752997bf21844c4ec2bd0d22&session_login_hash=fecd7825582b6d038d288f67c368090aa369c85d&url=OTFhY1hFRkYDHk4UR0YcV0xaEwweUkgZXEMTDEIeU1VaVBIQb1RARFZDTxNYQQ1YVm4FCkIMAzAxMjY%3D
Content-Encoding    gzip
Content-Length  26
Keep-Alive  timeout=2, max=9999
Connection  Keep-Alive
Content-Type    text/html; charset=UTF-8

You'll need to grab the URL location and the cookie it sets ("ws2"). Then you'll need to drop onto that redirect URL you grabbed, and get the rest of the cookies it sets, which are ws2, stsd_refr, and qeppo_login.

You then need to fill in the POST body with the form elements as mentioned above and in the links you provided.

Not knowing anything about this site you're trying to log into, I'd venture a guess that if you don't get good session variables and cookies and include them for each of your logical requests, your login attempts may fail.

Long story short, just use Fiddler or Firebug to capture what a login session looks like, and mimic it using the techniques you've already seen.

这篇关于使用C#登录网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆