Page 2 of 2

Re: Error trying to download the V1 and V2 files with current version number

Posted: 13 May 2024, 09:40
by joedf
I feel that... 99% of my stuff is still v1.1 :P

Re: Error trying to download the V1 and V2 files with current version number

Posted: 13 May 2024, 10:01
by lmstearn
All the files e.g this one won't work with URLDownloadToFile.
https://www.autohotkey.com/assets/images/ahk_wallpaper_reduced.jpg
Think it's related to this issue with the challenge pages from Cloudflare, one way around it might be a different user agent.

Re: Error trying to download the V1 and V2 files with current version number

Posted: 22 May 2024, 09:50
by tank
I havent forgotten this. I even tried with the autohotkey user agent in postman and it worked fine. For the life of me I cannot tell what it is. unless this is something much lower level like how AHK actually impliments under the hood that is now being subverted by OS. but thats pretty difficult to accept.

Re: Error trying to download the V1 and V2 files with current version number

Posted: 22 May 2024, 13:44
by joedf
@lexikos Any ideas? We're not sure if it's the server configs or if it's AHK... :think:

Re: Error trying to download the V1 and V2 files with current version number

Posted: 22 May 2024, 18:38
by JoeWinograd
Hi @tank and @joedf,
Thanks for your continuing efforts on this...much appreciated! Hopefully, @lexikos can provide some ideas to help resolve the problem. Regards, Joe

Re: Error trying to download the V1 and V2 files with current version number

Posted: 23 May 2024, 22:46
by lexikos
What would I know? Download just uses a few Internet functions from wininet, as anyone can see.

Re: Error trying to download the V1 and V2 files with current version number

Posted: 26 May 2024, 09:13
by Descolada
This problem affects the download prompt caused by #Requires AutoHotkey ... as well, which fails with error "Download failed."

The failure is caused by InternetOpenUrl which fails with error ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, so it appears there is some kind of problem with the certificate.
Downloading via a GET request with Msxml2.XMLHTTP doesn't seem to be affected.

Re: Error trying to download the V1 and V2 files with current version number

Posted: 26 May 2024, 16:52
by TAC109
TAC109 wrote:
01 May 2024, 00:51
I’m also having problems using UrlDownloadToFile on https://www.autohotkey.com/mpress/mpress.219.zip, used in the Ahk2Exe Updater.
I’ve since made changes to the Ahk2Exe Updater to avoid this problem. Mpress is now downloaded from GitHub.

Cheers

Re: Error trying to download the V1 and V2 files with current version number

Posted: 26 May 2024, 18:46
by JoeWinograd
Descolada wrote:Downloading via a GET request with Msxml2.XMLHTTP doesn't seem to be affected.
Hi Descolada,
Could you post a V1 and/or V2 code snippet with that method? Thanks much, Joe

Re: Error trying to download the V1 and V2 files with current version number

Posted: 26 May 2024, 23:13
by Descolada
@JoeWinograd
If you only need the version number without downloading a file:

Code: Select all

req := ComObject("Msxml2.XMLHTTP")
req.open("GET", "https://www.autohotkey.com/download/2.0/version.txt", 0)
req.send()

if req.status == 200
  MsgBox "AHK 2.0 version: " req.responseText
else
  MsgBox "Failed to get AHK version"
Download to file (variant 1):

Code: Select all

DownloadURL("https://www.autohotkey.com/download/2.1/AutoHotkey_2.1-alpha.12_setup.exe")
ExitApp

DownloadURL(url, filename?) {
    local oStream, req := ComObject("Msxml2.XMLHTTP")
    req.open("GET", url, true)
    req.send()
    while req.readyState != 4
        Sleep 100

    if req.status == 200 {
        oStream := ComObject("ADODB.Stream")
        oStream.Open()
        oStream.Type := 1
        oStream.Write(req.responseBody)
        oStream.SaveToFile(filename ?? StrSplit(url, "/")[-1], 2)
        oStream.Close()
    } else
        throw Error("Download failed",, url)
}
Download to file (variant 2):

Code: Select all

DownloadURL("https://www.autohotkey.com/download/2.1/AutoHotkey_2.1-alpha.12_setup.exe")
ExitApp

DownloadURL(url, filename?) {
    local f, req := ComObject("Msxml2.XMLHTTP")
    req.open("GET", url, true)
    req.send()
    while req.readyState != 4
        Sleep 100

    if req.status == 200 {
        f := FileOpen(filename ?? StrSplit(url, "/")[-1], "w")
        f.RawWrite(NumGet(req.responseBody.ptr + 8 + A_PtrSize, "ptr"), req.responseBody.MaxIndex()+1)
        f.Close()
    } else
        throw Error("Download failed",, url)
}
EDIT: improved variant 2 speed.

Re: Error trying to download the V1 and V2 files with current version number

Posted: 27 May 2024, 03:07
by lexikos
Descolada wrote:
26 May 2024, 09:13
The failure is caused by InternetOpenUrl which fails with error ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, so it appears there is some kind of problem with the certificate.
That error means "The server is requesting client authentication." as in "give me a certificate that proves your identity". Apparently, if the server does not require authentication but requests it, you must send the request again with the same handles to "authenticate" anonymously.

Re: Error trying to download the V1 and V2 files with current version number

Posted: 27 May 2024, 10:17
by joedf

Re: Error trying to download the V1 and V2 files with current version number

Posted: 27 May 2024, 10:54
by Descolada
@lexikos can confirm, changing script_autoit.cpp from

Code: Select all

	// Open the required URL
	HINTERNET hFile = InternetOpenUrl(hInet, aURL, NULL, 0, flags_for_open_url, 0);
	if (!hFile)
	{
		DWORD last_error = GetLastError(); // Save this before calling InternetCloseHandle, otherwise it is set to 0.
		InternetCloseHandle(hInet);
		return FR_E_WIN32(last_error);
	}
to

Code: Select all

	// Open the required URL
	HINTERNET hFile = InternetOpenUrl(hInet, aURL, NULL, 0, flags_for_open_url, 0);
	if (!hFile)
	{
		hFile = InternetOpenUrl(hInet, aURL, NULL, 0, flags_for_open_url, 0);
		if (!hFile)
		{
			DWORD last_error = GetLastError(); // Save this before calling InternetCloseHandle, otherwise it is set to 0.
			InternetCloseHandle(hInet);
			return FR_E_WIN32(last_error);
		}
	}
fixes the issue.

Re: Error trying to download the V1 and V2 files with current version number

Posted: 27 May 2024, 14:14
by joedf
Thanks for figuring this out @Descolada :+1:

Re: Error trying to download the V1 and V2 files with current version number

Posted: 27 May 2024, 20:33
by JoeWinograd
Hi @Descolada,
I can't speak to your fix of changing script_autoit.cpp, but I can say that your three scripts (version number without downloading a file, download variant 1, download variant 2) all work perfectly! Thank you very much for writing and posting them...I really appreciate it! Regards, Joe

Re: Error trying to download the V1 and V2 files with current version number

Posted: 28 May 2024, 16:48
by lexikos
@Descolada When I tested yesterday, both the first and second call returned error 12044. Today it works.

Re: Error trying to download the V1 and V2 files with current version number

Posted: 30 May 2024, 21:20
by lexikos
v2.0.16 implements the workaround for ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED.

Re: Error trying to download the V1 and V2 files with current version number

Posted: 31 May 2024, 07:44
by joedf
lexikos wrote:
30 May 2024, 21:20
v2.0.16 implements the workaround for ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED.
:thumbup: :thumbup: :thumbup:

Re: Error trying to download the V1 and V2 files with current version number

Posted: 05 Jun 2024, 08:54
by Descolada
lexikos wrote:
28 May 2024, 16:48
@Descolada When I tested yesterday, both the first and second call returned error 12044. Today it works.
Now it doesn't work again, fails with error 12044. Weird...

EDIT: and it started working again. It failed in 2.0.16, then I installed 2.1-alpha.13 and it suddenly started working. I uninstalled 2.1-alpha.13 and went back to 2.0.16, it continued working (even after rebooting). I'm guessing there is some kind of issue remaining, but I have no clue what may be causing it.