以编程方式获取.ASPXAUTH cookie值 [英] Get the .ASPXAUTH cookie value programatically
问题描述
有一种方法可以以程序方式获取.ASPXAUTH值。
示例使用我自己的凭据登录到网站,然后阅读响应。 .it不返回用于跟踪会话的CookieContainer中的.APSXAUTH。
任何人都有一个线索,如何获得它,并发送它与随后的获取
这里是我做的更具体的:- 向页面发送HTTP GET。读取_VIEWSTATE等值。
- 向登录页面发送HTTP POST。
- 服务器向某个默认页面发送302响应(重定向)。
因此,我认为可能有比这更好的方法track session:
CookieContainer _cookieJar = new CookieContainer();
HttpWebRequest request =(HttpWebRequest)WebRequest.Create(_url);
request.CookieContainer = _cookieJar;
所以总结答案:
如果您尝试通过自己的应用程序在基于表单的身份验证网站上通过程序登录,请确保您按照跟踪Cookie的步骤操作。
首先创建一个初始 GET
请求,然后执行后续 POST
请求请求和响应应该以这种方式表示:
HttpWebRequest request =(HttpWebRequest)WebRequest.Create(_url) ;
request.CookieContainer = _cookieJar;
HttpWebResponse httpsResponse =(HttpWebResponse)request.GetResponse();
CookieContainer
。
如果你的回答是用Gzip编码的,只需要加入以下行:
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;在调用 request.GetResponse()之前
希望这有助于某人。
Is there a way to get the .ASPXAUTH value programatically.
Example I login to a website with my own credentials (POST) and then read the response...it does not return the .APSXAUTH in the CookieContainer that I use to track the session.
Anyone has a clue how can I get it and send it with the subsequent gets and posts?
[EDIT] Here's what I do to be more specific:
- send a HTTP GET to a page. read values like _VIEWSTATE etc.
- send a HTTP POST to the Login page. It includes the login information.
- The server sends a 302 response (redirect) to some Default page. The forms authentication cookie is supposed to be included but it's not.
So I was thinking that there might be a better way than this to track session:
CookieContainer _cookieJar = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
request.CookieContainer = _cookieJar;
So the summarize the answer:
If you're trying to login programatically on a Forms based authentication website trough your own application make sure you follow the steps you take that track the cookies.
First create a initial GET
request, and then do the subsequential POST
requests that will do the postback.The request and the responses should be formulated in this way:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
request.CookieContainer = _cookieJar;
HttpWebResponse httpsResponse = (HttpWebResponse)request.GetResponse();
The CookieContainer
class handles the cookies as expected.
And if your response is encoded with Gzip just include the following line:
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
before you call request.GetResponse()
Hope this helps someone out there.
这篇关于以编程方式获取.ASPXAUTH cookie值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!