UrlDownloadToFile documentation

Report problems with documented functionality
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

UrlDownloadToFile documentation

01 May 2017, 20:30

I think there is an error in Example: Make an asynchronous HTTP request.
Example: Make an asynchronous HTTP request.

req := ComObjCreate("Msxml2.XMLHTTP")
; Open a request with async enabled.
req.open("GET", "https://autohotkey.com/download/1.1/version.txt", true)
; Set our callback function (v1.1.17+).
req.onreadystatechange := Func("Ready")
; Send the request. Ready() will be called when it's complete.
req.send()
/*
; If you're going to wait, there's no need for onreadystatechange.
; Setting async=true and waiting like this allows the script to remain
; responsive while the download is taking place, whereas async=false
; will make the script unresponsive.
while req.readyState != 4
sleep 100
*/
#Persistent

Ready() {
global req
if (req.readyState != 4) ; Not done yet.
return
if (req.status == 200 || req.status == 304) ; OK.
MsgBox % "Latest AutoHotkey version: " req.responseText
else
MsgBox 16,, % "Status " req.status
ExitApp
}
If req.status will be 304 it will not be OK, because server will not send You message body with this answer.
Not Modified 304
If the client has done a conditional GET and access is allowed, but the document has not been modified since the date and time specified in If-Modified-Since field, the server responds with a 304 status code and does not send the document body to the client.
https://www.w3.org/Protocols/HTTP/HTRESP.html

Code: Select all

url := "https://autohotkey.com/download/1.1/version.txt"
HTTP := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
HTTP.Open("GET", url)
HTTP.Send()
date:= HTTP.getResponseHeader("Last-Modified")
msgbox % HTTP.Status
msgbox % HTTP.ResponseText
HTTP.Open("GET", url)
HTTP.SetRequestHeader("If-Modified-Since", date)
HTTP.Send()
msgbox % HTTP.Status
msgbox % HTTP.ResponseText
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: UrlDownloadToFile documentation

02 May 2017, 02:30

Good thing the example does not do a conditional GET...

I'll remove the check.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 43 guests