Download using COM

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Iskander
Posts: 23
Joined: 07 Feb 2017, 06:30

Download using COM

23 Apr 2022, 22:49

Hi. How can I download the link with "Winhttprequest.5.1", or with "MSXML2.xmlhttp.6.0"? —

Code: Select all

WinHTTP := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
;WinHTTP := ComObjCreate("Msxml2.XMLHTTP.6.0")
WinHTTP.Open("GET", "https://api.europeana.eu/record/473/https___www_esbirky_cz_detail_328612.json?wskey=nLbaXYaiH", 1)
 
WinHTTP.SetRequestHeader("Upgrade-Insecure-Requests","1")
WinHTTP.SetRequestHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36")
WinHTTP.SetRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
WinHTTP.SetRequestHeader("Sec-Fetch-Site","none")
WinHTTP.SetRequestHeader("Sec-Fetch-Mode","navigate")
WinHTTP.SetRequestHeader("Sec-Fetch-User","?1")
WinHTTP.SetRequestHeader("Sec-Fetch-Dest","document")
WinHTTP.SetRequestHeader("Accept-Encoding","gzip, deflate, br")
WinHTTP.SetRequestHeader("Accept-Language","ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7")
WinHTTP.SetRequestHeader("referer","https://api.europeana.eu")
WinHTTP.SetRequestHeader("Cache-Control","max-age=0")
WinHTTP.SetRequestHeader("If-Modified-Since","Mon, 31 Jan 2022 11:04:15 GMT")
 
WinHTTP.Send()
WinHTTP.WaitForResponse()
RTxt := WinHTTP.ResponseText
Last edited by BoBo on 23 Apr 2022, 23:20, edited 1 time in total.
Reason: Added missing subject line.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Download using COM

24 Apr 2022, 00:27

Code: Select all

URLDownloadToFile,https://api.europeana.eu/record/473/https___www_esbirky_cz_detail_328612.json?wskey=nLbaXYaiH,tempfile12345.txt
run, tempfile12345.txt
ExitApp
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Download using COM

24 Apr 2022, 00:32

Iskander, do You understand what does "If-Modified-Since" header?
Iskander
Posts: 23
Joined: 07 Feb 2017, 06:30

Re: Download using COM

24 Apr 2022, 05:49

Sorry my english.

malcev, no, but I guess that it is superfluous, and I tried without it.

AHKStudent, I have for Win7 x64 does not work for download. Is it possible in the GET-requests format?
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Download using COM

24 Apr 2022, 06:13

If You look at Your earlier topics, then You will see that You already know how to download using com.
viewtopic.php?f=76&t=100261
Iskander
Posts: 23
Joined: 07 Feb 2017, 06:30

Re: Download using COM

24 Apr 2022, 06:53

malcev, how there does not download on the link too:

Code: Select all

;HTTP := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
HTTP := ComObjCreate("Msxml2.XMLHTTP.6.0")

HTTP.Open("GET", "https://api.europeana.eu/record/473/https___www_esbirky_cz_detail_328612.json?wskey=nLbaXYaiH", 0)

HTTP.SetRequestHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36")
HTTP.SetRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
HTTP.SetRequestHeader("Sec-Fetch-Site","none")
HTTP.SetRequestHeader("Sec-Fetch-Mode","navigate")
HTTP.SetRequestHeader("Sec-Fetch-User","?1")
HTTP.SetRequestHeader("Sec-Fetch-Dest","document")
;HTTP.SetRequestHeader("Accept-Encoding","gzip, deflate, br")
;HTTP.SetRequestHeader("Upgrade-Insecure-Requests","1")
;HTTP.SetRequestHeader("Accept-Language","ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7")
HTTP.SetRequestHeader("referer","https://api.europeana.eu")
;HTTP.SetRequestHeader("Cache-Control","max-age=0")

HTTP.Send()
;HTTP.WaitForResponse()
Body := HTTP.ResponseBody
pData := NumGet(ComObjValue(Body), A_PtrSize = 8? 16:12, "ptr")
File := FileOpen(A_ScriptDir "\" a_now ".txt", "w")
File.RawWrite(pData + 0, Body.MaxIndex() + 1)
File.Close()
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Download using COM

24 Apr 2022, 07:12

For me it works.
Iskander
Posts: 23
Joined: 07 Feb 2017, 06:30

Re: Download using COM

24 Apr 2022, 07:34

And I only have this site (with "api": "api.europeana.eu") does not work, everything else download. And if remove the "api." from link —

Code: Select all

HTTP.Open("GET", "https://europeana.eu/record/473/https___www_esbirky_cz_detail_328612.json?wskey=nLbaXYaiH", 0)
download the text: "{}".
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Download using COM

24 Apr 2022, 08:33

Iskander wrote:
24 Apr 2022, 07:34
And I only have this site (with "api": "api.europeana.eu") does not work, everything else download. And if remove the "api." from link —

Code: Select all

HTTP.Open("GET", "https://europeana.eu/record/473/https___www_esbirky_cz_detail_328612.json?wskey=nLbaXYaiH", 0)
download the text: "{}".
That is exactly what you get if you visit the url so it means its working :thumbup:
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Download using COM

24 Apr 2022, 08:56

Iskander, forget about win7, use win10.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Draken, oktavimark and 401 guests