Usually you would do a HEAD request instead of GET in this case, but when you do that, you won't get the Content-Disposition header.
I think that httpRequest.ahk is able to downlaod the file through a buffer sothat it won't overload your RAM:
http://www.autohotke...hk-lunicodex64/
If you want to do it yourself you might wanna check out the winhttp api. I wrote this function a while ago (big creadits to RHCP who teached me a lot about DllCalls):
HttpRequest(url,method:="",headers:="",ByRef body:="",proxy:="",pExcludeList:="",httpVersion:="",sessionOptions:="",requestOptions:="") {
;Makes working with the msdn functions easier
static LPCWSTR:="UPTR"
static DWORD:="UInt"
static LPCVOID:="UPTR"
static LPDWORD:="UPTR"
static HINTERNET:="UPTR"
static INTERNET_PORT:="UShort"
static DWORD_PTR:="UPTR"
static LPVOID:="UPTR"
static NULL := 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Not supported so far
asynch := False
VarSetCapacity(callbackValue,A_PtrSize)
;;;;;;;;;;;;;;;;;;;;;
;Crack URL to use it's segments in the upcomming DllCalls
VarSetCapacity(myStruct,60,0)
numput(60,myStruct,0,"Uint") ; this dll function requires this to be set
numput(1,myStruct,8,"Uint") ; SchemeLength
numput(1,myStruct,20,"Uint") ; HostNameLength
;numput(1,myStruct,32,"Uint") ; UserNameLength
;numput(1,myStruct,40,"Uint") ; PasswordLength
numput(1,myStruct,48,"Uint") ; UrlPathLength
numput(1,myStruct,56,"Uint") ; ExtraInfoLength
DllCall("Winhttp.dll\WinHttpCrackUrl","PTR",&url,"UInt",StrLen(url),"UInt",0,"PTR",&myStruct)
scheme := StrGet(NumGet(myStruct,4,"Ptr"),NumGet(myStruct,8,"UInt"))
;userName := StrGet(NumGet(myStruct,28,"Ptr"),NumGet(myStruct,32,"UInt"))
;password := StrGet(NumGet(myStruct,36,"Ptr"),NumGet(myStruct,40,"UInt"))
hostName := StrGet(NumGet(myStruct,16,"Ptr"),NumGet(myStruct,20,"UInt"))
port := NumGet(myStruct,24,"Int")
urlPath := StrGet(NumGet(myStruct,44,"Ptr"),NumGet(myStruct,48,"UInt"))
extraInfo := StrGet(NumGet(myStruct,52,"Ptr"),NumGet(myStruct,56,"UInt"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Make the url parts usable
If (scheme = "https") {
port := (port) ? port : 443
https := True
} Else
https := False
resource := urlPath . extraInfo
;;;;;;;;;;;;;;;;;;;;;;;;;;
;Parse headers and convert them to be usable
addHeaders := ""
acceptedTypes := []
For header, value in headers
{
If (header = "User-Agent")
userAgent := value
Else If (header = "Referer")
referrer := value
Else If (header = "Accept") {
Loop, parse, acceptedTypes, `;
acceptedTypes.Insert(value)
} Else If (header = "Content-Length")
bodySize := value
Else
addHeaders .= header . ": " . value . "`r`n"
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Parse proxy exclude list and make it usable
proxyBypassString := ""
Loop, % pExcludeList.MaxIndex()
proxyBypassString .= pExcludeList[A_Index] . ";"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Initialize WinHttp application
hSession := DllCall("Winhttp.dll\WinHttpOpen"
,LPCWSTR,&userAgent
,DWORD, (proxy) ? 3 : 1
,LPCWSTR,&proxy
,LPCWSTR,(pExcludeList) ? pExcludeList : NULL
,DWORD,asynch)
If (!hSession)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"WinHttp initialization failed"} ;Msgbox,, hSession, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Set session options
For optionKey, optionValue in sessionOptions
{
oResult := DllCall("Winhttp.dll\WinHttpSetOption"
,HINTERNET,hConnect
,DWORD,optionKey
,LPVOID,&optionValue
,DWORD,StrLen(optionValue))
If !(oResult)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Setting session option #" . A_Index . " failed"}
}
;;;;;;;;;;;;;;;;;;;;
;Specify target server
hConnect := DllCall("Winhttp.dll\WinHttpConnect"
,HINTERNET,hSession
,LPCWSTR,&hostName
,INTERNET_PORT,port
,DWORD,0)
If (!hConnect)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Creating connect handle failed"} ;Msgbox,, hConnect, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;
;Create request handle
hRequest := DllCall("Winhttp.dll\WinHttpOpenRequest"
,HINTERNET,hConnect
,LPCWSTR,(method) ? &method : NULL
,LPCWSTR,(resource) ? &resource : NULL
,LPCWSTR,(httpVersion) ? &httpVersion : NULL
,LPCWSTR,(referrer) ? &referrer : NULL
,LPCWSTR,(acceptedTypes.MaxIndex()) ? &acceptedTypes : NULL
,DWORD,(https) ? 0x00800000 : NULL)
If (!hRequest)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Creating request handle failed"} ;Msgbox,, hRequest, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;
;Set request options
For optionKey, optionValue in requestOptions
{
oResult := DllCall("Winhttp.dll\WinHttpSetOption"
,HINTERNET,hConnect
,DWORD,optionKey
,LPVOID,&optionValue
,DWORD,StrLen(optionValue))
If !(oResult)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Setting request option #" . A_Index . " failed"}
}
;;;;;;;;;;;;;;;;;;;;
;Send request to server
bResults := DllCall("Winhttp.dll\WinHttpSendRequest"
,HINTERNET,hRequest
,LPCWSTR,&addHeaders
,DWORD,StrLen(addHeaders)
,LPVOID,&body
,DWORD,(bodySize) ? bodySize : StrLen(body)*2
,DWORD,(bodySize) ? bodySize : StrLen(body)*2
,DWORD_PTR,&callbackValue)
If (!bResults)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Sending the request failed"} ; Msgbox,, bResults 1, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;
;Receive server response
bResults := DllCall("Winhttp.dll\WinHttpReceiveResponse"
,HINTERNET,hRequest
,LPVOID,NULL)
If (!bResults)
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Receiving server response failed"} ; Msgbox,, bResults 1, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
;;;;;;;;;;;;;;;;;;;;;;;;
;Receive the response body
responseBody := ""
VarSetCapacity(dwDownloaded,8)
Loop {
dwSize := 0
If (!DllCall("Winhttp.dll\WinHttpQueryDataAvailable"
,HINTERNET,hRequest
,LPDWORD,&dwSize)) {
Return % {Body:"",Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Getting info about available response data failed"} ;Msgbox,, hRequest, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
} Else
dwSize := Asc(dwSize)
If (!dwSize)
Break
VarSetCapacity(pszOutBuffer,Asc(dwSize)+1,0)
If (!DllCall("Winhttp.dll\WinHttpReadData"
,HINTERNET,hRequest
,LPVOID,&pszOutBuffer
,DWORD,dwSize
,LPDWORD,&dwDownloaded)) {
MsgBox % "error:" A_LastError
} Else {
Loop, % Asc(dwDownloaded)
responseBody .= Chr(NumGet(&pszOutBuffer,A_Index-1,"UChar"))
}
If (!dwDownloaded)
break
If (dwSize <= 0)
Break
}
;;;;;;;;;;;;;;;;;;;;;;;;;;
;Receive response headers
dwSize := 0
bResults := DllCall("Winhttp.dll\WinHttpQueryHeaders"
,HINTERNET,hRequest
,DWORD,22 ;raw
,LPCWSTR, NULL
,LPVOID, NULL
, "UIntP", dwSize
;,LPDWORD, &dwSize
,LPDWORD, NULL)
If (!bResults && A_LastError != 122) ; allow function to proceed if it was a buffer size error
Return % {Body:responseBody,Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Getting the size of the response headers failed"}
If (A_LastError = 122) { ;buffer too small
;lpOutBuffer := new WCHAR[dwSize/sizeof(WCHAR)]
VarSetCapacity(lpOutBuffer, dwSize, 0)
bResults := DllCall("Winhttp.dll\WinHttpQueryHeaders"
,HINTERNET,hRequest
,DWORD,22 ;raw
,LPCWSTR,NULL
,LPVOID, &lpOutBuffer
,"UIntP", dwSize
,LPDWORD, NULL)
}
If (!bResults)
Return % {Body:responseBody,Headers:{},StatusCode:0,StatusText:"",HttpVersion:"",Error:"Receiving responseheaders failed"} ;Msgbox,, hRequest, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
VarSetCapacity(lpOutBuffer, -1) ; update the internal string length - otherwise script will crash
;;;;;;;;;;;;;;;;;;;;;;;;;
;Parse received statusline and request headers
responseHeaders := Object()
requestLine := Array()
Loop, parse, lpOutBuffer, `n, `r
{
If (!A_LoopField)
Continue
If (A_Index = 1) {
Loop, parse, A_LoopField, %A_Space%
requestLine[A_Index] := A_LoopField
} Else
responseHeaders.Insert(SubStr(A_LoopField,1,InStr(A_LoopField,": ")-1), SubStr(A_LoopField,InStr(A_LoopField,": ")+2))
}
responseHttpVersion := requestLine[1]
statusCode := requestLine[2]
statusText := requestLine[3]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If (A_LastError || ErrorLevel)
Return % {Body:responseBody,Headers:responseHeaders,StatusCode:statusCode,StatusText:statusText,HttpVersion:responseHttpVersion,Error:"An error occurred"} ;Msgbox,, hRequest, LastError: %A_LastError%`nErrorLevel: %ErrorLevel%
Return % {Body:responseBody,Headers:responseHeaders,StatusCode:statusCode,StatusText:statusText,HttpVersion:responseHttpVersion,Error:""}
}
You won't be able to save binary data with it, but it shows how you can retrive the responsebody in a loop with a buffer.
But this is really complicated stuff and right now I don't have the time to find out what exactly you would need to change.
The functions are documented here: http://msdn.microsof...7(v=vs.85).aspx
You might also want to check out the C++ examples on the site.