If req.status will be 304 it will not be OK, because server will not send You message body with this answer.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
}
https://www.w3.org/Protocols/HTTP/HTRESP.htmlNot 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.
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