how to catch the cookie

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

how to catch the cookie

24 Sep 2017, 04:08

Code: Select all

#NoEnv
#SingleInstance force
url:="http://www.duxiu.com/loginhl.jsp?send=true&UserName=shr&PassWord=shr"
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")

WebRequest.Open("GET",url)
WebRequest.SetRequestHeader("Referer",url)
WebRequest.SetRequestHeader("Accept-Language","zh-cn")
WebRequest.SetRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)")
WebRequest.AllowAutoRedirect := false
WebRequest.Send()

Msgbox % WebRequest.GetResponseHeader("Set-Cookie: ",cookie) ;获取登录后的cookie

it can work,but can't catch the cookie I need.
newscreen29589265.jpg
newscreen29589265.jpg (72.92 KiB) Viewed 1795 times
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: how to catch the cookie

24 Sep 2017, 09:51

I'm not certain if this will solve your problem, but maybe it will give you a hint.

I had a similar issue trying to log in to a page with HttpRequest. I found that if I sent all the login details (password/username) right away, it always failed. I first needed to SEND the URL without the login details to load the login page and appropriate cookies, then I send the login details (loginBody) after that.

Example excerpt from a script I use:

Code: Select all

;...

loginURL := "https://www.<mypage>.net/user/login.php"
loginBody := "submit=true&phrase=&uname=<myusername>&pwd=<mypassword>"

;First, visit the login page - this seems to set the required cookies
s_httpRequest.Open("GET", loginURL)
s_httpRequest.Send()

;Next, POST the login form info
s_httpRequest.Open("POST", loginURL)
s_httpRequest.SetRequestHeader("Content-Type","application/x-www-form-urlencoded") ;application/x-www-form-urlencoded
s_httpRequest.Send(loginBody)
			
;...
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

Re: how to catch the cookie

25 Sep 2017, 09:32

thanks.
I want to set WebRequest.AllowAutoRedirect := false ,but it doesn't works.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: how to catch the cookie

05 Oct 2017, 02:29

The WinHttpRequest object doesn't have AllowAutoRedirect property. But you can use Option property:

Code: Select all

WebRequest.Option(6) := false ; 6 = WinHttpRequestOption_EnableRedirects
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384108(v=vs.85).aspx wrote:

Code: Select all

typedef enum WinHttpRequestOption { 
  WinHttpRequestOption_UserAgentString,
  WinHttpRequestOption_URL,
  WinHttpRequestOption_URLCodePage,
  WinHttpRequestOption_EscapePercentInURL,
  WinHttpRequestOption_SslErrorIgnoreFlags,
  WinHttpRequestOption_SelectCertificate,
  WinHttpRequestOption_EnableRedirects,
  WinHttpRequestOption_UrlEscapeDisable,
  WinHttpRequestOption_UrlEscapeDisableQuery,
  WinHttpRequestOption_SecureProtocols,
  WinHttpRequestOption_EnableTracing,
  WinHttpRequestOption_RevertImpersonationOverSsl,
  WinHttpRequestOption_EnableHttpsToHttpRedirects,
  WinHttpRequestOption_EnablePassportAuthentication,
  WinHttpRequestOption_MaxAutomaticRedirects,
  WinHttpRequestOption_MaxResponseHeaderSize,
  WinHttpRequestOption_MaxResponseDrainSize,
  WinHttpRequestOption_EnableHttp1_1,
  WinHttpRequestOption_EnableCertificateRevocationCheck
} WinHttpRequestOption;
Also, Msgbox % WebRequest.GetResponseHeader("Set-Cookie: ",cookie) is incorrect. Use Msgbox % cookie := WebRequest.GetResponseHeader("Set-Cookie") instead.
xuezhe
Posts: 91
Joined: 06 Jan 2016, 11:02

Re: how to catch the cookie

05 Oct 2017, 04:30

你真是太厉害啦。非常感谢。

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww and 340 guests