Is there a reliable way to get cookies?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Is there a reliable way to get cookies?

16 Feb 2019, 12:30

Hello,

Is there a reliable way to get cookies? Or can I capture the request header or command line tool?

Although I can get cookies by using "InternetGetCookieExW", it is not very reliable, and it often happens that nothing can be obtained.

Does anyone have any suggestions?

Thanks.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Is there a reliable way to get cookies?

18 Feb 2019, 00:28

From which application do You need cookies?
It is strange that InternetGetCookieExW does not work - post Your code here.
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: Is there a reliable way to get cookies?

18 Feb 2019, 06:20

Such as the following example. It doesn't seem to be available from many websites.

Code: Select all

URL := "https://www.autohotkey.com/"
Cookie := GetCookie(URL)
msgbox % Cookie
return


GetCookie(ByRef str)
{
	DllCall("Wininet.dll\InternetGetCookieExW"
						, "ptr",	&str
						, "ptr",	0
						, "ptr",	0
						, "ptr*",	Size
						, "str",	"INTERNET_COOKIE_HTTPONLY"
						, "ptr",	0)

	VarSetCapacity(CookieData, Size)

	DllCall("Wininet.dll\InternetGetCookieExW"
						, "ptr",	&str
						, "ptr",	0
						, "ptr",	&CookieData
						, "ptr*",	Size
						, "str",	"INTERNET_COOKIE_HTTPONLY"
						, "ptr",	0)

	return, StrGet(&CookieData)
}
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Is there a reliable way to get cookies?

18 Feb 2019, 07:10

It does not work because it is wrong.

Code: Select all

InternetGetCookieEx(URL) {
	Loop, 2 {
		if (A_Index = 2) {
			VarSetCapacity(cookieData, size, 0)
		}
		DllCall( "Wininet.dll\InternetGetCookieEx"
		       , "ptr", &URL, "ptr", 0, "ptr", &cookieData, "int*", size
		       , "uint", 8192 ; INTERNET_COOKIE_HTTPONLY
		       , "ptr", 0 )
	}
	return StrGet(&cookieData)
}
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: Is there a reliable way to get cookies?

18 Feb 2019, 09:47

Have you tried it? I tried your code and it still doesn't work.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Is there a reliable way to get cookies?

18 Feb 2019, 09:49

For me it works.
Open site in IE and run this script.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], kingina and 205 guests