<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=9592&amp;type=atom" />
	<updated>2018-09-29T23:46:34Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=9592</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=128944#p128944" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Небольшое исправление:<br /></p><div class="codebox"><pre><code>HttpQueryInfo(URL, QueryInfoFlag=21, Proxy=&quot;&quot;, ProxyBypass=&quot;&quot;)
{
   hModule := DllCall(&quot;LoadLibrary&quot;, Str, &quot;wininet.dll&quot;, Ptr)
   AccessType := Proxy = &quot;&quot; ? 1 : 3
   
   Loop 1
   {
      if !io_hInternet := DllCall(&quot;wininet\InternetOpen&quot;, Str, &quot;&quot;, UInt, AccessType, Str, Proxy, Str, ProxyBypass, UInt, 0, Ptr) ;dwFlags
         break
      
      if !iou_hInternet := DllCall(&quot;wininet\InternetOpenUrl&quot;, Ptr, io_hInternet, Str, url, Str, &quot;&quot;, UInt, 0, UInt, 0x80000000, UInt, 0)
         break
      
      VarSetCapacity(buffer_len, 4, 0) 
      Loop
      {         
         if A_Index = 3
            break 2
         
         VarSetCapacity(buffer, NumGet(buffer_len, &quot;UInt&quot;))
         hqi := DllCall(&quot;wininet\HttpQueryInfo&quot;, Ptr, iou_hInternet, UInt, QueryInfoFlag, Ptr, &amp;buffer, Ptr, &amp;buffer_len, UInt, 0)
      } Until hqi
      success := 1
   }
   
   DllCall(&quot;wininet\InternetCloseHandle&quot;,  Ptr, iou_hInternet)
   DllCall(&quot;wininet\InternetCloseHandle&quot;,  Ptr, io_hInternet)
   DllCall(&quot;FreeLibrary&quot;, Ptr, hModule)
   
   Return, success ? StrGet(&amp;buffer) : -1
}</code></pre></div><p>Один <em>success</em> вместо двух <em>Error</em>.</p></blockquote></div><p>Тут ошибка:<br /></p><div class="codebox"><pre><code>link := &quot;https://www.google.com/maps/vt/pb=!1m5!1m4!1i12!2i4645!3i2509!4i128!2m2!1e1!3i810!3m9!2sru!3slv!5e1105!12m1!1e4!12m1!1e47!12m1!1e3!4e0!5m1!1e0!23i4111425!23i1358757!23i1358902&quot;
msgbox % HttpQueryInfo(link)


HttpQueryInfo(URL, QueryInfoFlag=21, Proxy=&quot;&quot;, ProxyBypass=&quot;&quot;)
{
   hModule := DllCall(&quot;LoadLibrary&quot;, Str, &quot;wininet.dll&quot;, Ptr)
   AccessType := Proxy = &quot;&quot; ? 1 : 3
   
   Loop 1
   {
      if !io_hInternet := DllCall(&quot;wininet\InternetOpen&quot;, Str, &quot;&quot;, UInt, AccessType, Str, Proxy, Str, ProxyBypass, UInt, 0, Ptr) ;dwFlags
         break
      
      if !iou_hInternet := DllCall(&quot;wininet\InternetOpenUrl&quot;, Ptr, io_hInternet, Str, url, Str, &quot;&quot;, UInt, 0, UInt, 0x80000000, UInt, 0)
         break
      
      VarSetCapacity(buffer_len, 4, 0) 
      Loop
      {         
         if A_Index = 3
            break 2
         
         VarSetCapacity(buffer, NumGet(buffer_len, &quot;UInt&quot;))
         hqi := DllCall(&quot;wininet\HttpQueryInfo&quot;, Ptr, iou_hInternet, UInt, QueryInfoFlag, Ptr, &amp;buffer, Ptr, &amp;buffer_len, UInt, 0)
      } Until hqi
      success := 1
   }
   
   DllCall(&quot;wininet\InternetCloseHandle&quot;,  Ptr, iou_hInternet)
   DllCall(&quot;wininet\InternetCloseHandle&quot;,  Ptr, io_hInternet)
   DllCall(&quot;FreeLibrary&quot;, Ptr, hModule)
   
   Return, success ? StrGet(&amp;buffer) : -1
}</code></pre></div><p>Чтобы такого избежать нужно указывать lpszAgent в InternetOpen запросе и чтобы не писать на диск, отправлять INTERNET_FLAG_NO_CACHE_WRITE:<br /></p><div class="codebox"><pre><code>link := &quot;https://www.google.com/maps/vt/pb=!1m5!1m4!1i12!2i4645!3i2509!4i128!2m2!1e1!3i810!3m9!2sru!3slv!5e1105!12m1!1e4!12m1!1e47!12m1!1e3!4e0!5m1!1e0!23i4111425!23i1358757!23i1358902&quot;
msgbox % HttpQueryInfo(link)


HttpQueryInfo(URL, QueryInfoFlag=21, Proxy=&quot;&quot;, ProxyBypass=&quot;&quot;)
{
   static hModule := DllCall(&quot;LoadLibrary&quot;, Str, &quot;wininet.dll&quot;, Ptr)
   AccessType := Proxy = &quot;&quot; ? 1 : 3
   
   Loop 1
   {
      if !io_hInternet := DllCall(&quot;wininet\InternetOpen&quot;, Str, &quot;autohotkey&quot;, UInt, AccessType, Str, Proxy, Str, ProxyBypass, UInt, 0, Ptr) ;dwFlags
         break
      
      if !iou_hInternet := DllCall(&quot;wininet\InternetOpenUrl&quot;, Ptr, io_hInternet, Str, url, Str, &quot;&quot;, UInt, 0, UInt, 0x84000000, UInt, 0)   ; INTERNET_FLAG_NO_CACHE_WRITE (0x04000000) + INTERNET_FLAG_RELOAD (0x80000000)
         break
      
      VarSetCapacity(buffer_len, 4, 0) 
      Loop
      {         
         if A_Index = 3
            break 2
         
         VarSetCapacity(buffer, NumGet(buffer_len, &quot;UInt&quot;))
         hqi := DllCall(&quot;wininet\HttpQueryInfo&quot;, Ptr, iou_hInternet, UInt, QueryInfoFlag, Ptr, &amp;buffer, Ptr, &amp;buffer_len, UInt, 0)
      } Until hqi
      success := 1
   }
   
   DllCall(&quot;wininet\InternetCloseHandle&quot;,  Ptr, iou_hInternet)
   DllCall(&quot;wininet\InternetCloseHandle&quot;,  Ptr, io_hInternet)
   DllCall(&quot;FreeLibrary&quot;, Ptr, hModule)
   
   Return, success ? StrGet(&amp;buffer) : -1
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-09-29T23:46:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=128944#p128944</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=128828#p128828" />
			<content type="html"><![CDATA[<p>Размер надёжней получать через MaxIndex().<br /></p><div class="codebox"><pre><code>url := &quot;https://www.dropbox.com/sh/j1msw4e8dup2c5q/AAANYUWXcyBDgxVGkveU7AFla?dl=1&quot;
;url := &quot;https://raw.githubusercontent.com/f5devcentral/f5-irule-editor/master/iRuler/Templates/Blank.txt&quot; ;1 byte
;url := &quot;https://raw.githubusercontent.com/SparkPost/java-sparkpost/master/src/main/resources/empty.txt&quot; ;0 bytes

req := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
req.Open(&quot;GET&quot;, url)
req.send()
msgbox % req.getallresponseheaders()
Body := req.ResponseBody
if IsObject(Body)
   length := Body.MaxIndex() + 1
else
   length := 0
msgbox % length</code></pre></div><p>Скачать используя буфер (не напрямую в память) можно либо, с ком объектами WinHttpRequest, XMLHTTP с использованием Range, что не везде поддерживается,<br />либо через WinInet, что и делает UrlDownloadToFile:<br /><a href="https://docs.microsoft.com/en-us/windows/desktop/api/wininet/nf-wininet-internetreadfile">https://docs.microsoft.com/en-us/window … etreadfile</a><br />либо WinHttp:<br /><a href="https://docs.microsoft.com/en-us/windows/desktop/api/winhttp/nf-winhttp-winhttpreaddata">https://docs.microsoft.com/en-us/window … tpreaddata</a><br />либо Urlmon:<br /><a href="https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms775123(v%3dvs.85)">https://docs.microsoft.com/en-us/previo … v%3dvs.85)</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-09-23T19:58:52Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=128828#p128828</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=128822#p128822" />
			<content type="html"><![CDATA[<p>HttpQueryInfo через com можно провернуть так:<br /></p><div class="codebox"><pre><code>url = https://github.com/szalony9szymek/large/releases/download/free/large
req := ComObjCreate(&quot;MSXML2.ServerXMLHTTP.6.0&quot;)
req.Open(&quot;GET&quot;, url, true)
req.send()
while req.readyState &lt;2   ; HEADERS_RECEIVED
   sleep 10
ResponseHeaders := req.GetAllResponseHeaders()
req.abort()
msgbox % ResponseHeaders</code></pre></div><p>С Microsoft.XMLHTTP, Msxml2.XMLHTTP, Msxml2.XMLHTTP.3.0, MSXML2.XMLHTTP.6.0, WinHttpRequest такого провернуть не всегда получится.<br />Ну и непонятно, почему мы считали, что после отправки запроса на сервер и после получения заголовков придется ждать получение тела ответа.<br /></p><div class="codebox"><pre><code>url = https://www.autohotkey.com/download/AutoHotkeyInstall.exe
req := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)

a := a_tickcount
req.Open(&quot;GET&quot;, url)
req.send()
req.GetAllResponseHeaders()
msgbox % a_tickcount - a

a := a_tickcount
req.ResponseBody
msgbox % a_tickcount - a</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-09-22T22:48:03Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=128822#p128822</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83780#p83780" />
			<content type="html"><![CDATA[<p>Разбираемся, как что работает, какие есть возможности.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-06-09T14:02:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83780#p83780</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83779#p83779" />
			<content type="html"><![CDATA[<p>Да всем устраивает, просто рассуждения о более коротком коде.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2014-06-09T13:46:31Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83779#p83779</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83778#p83778" />
			<content type="html"><![CDATA[<p>А чем HttpQueryInfo не устраивает?<br />В чем его минусы?</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2014-06-09T12:57:04Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83778#p83778</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83777#p83777" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Насколько помню, в этих случаях оно качает файл целиком. Если речь про гет запрос, без возможности сервера отдавать диапазонами.</p></blockquote></div><p>HttpQueryInfo вполне может и не качать. Как только скачались заголовки, функция может прекратить приём данных, т.к. ей больше ничего не нужно.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-06-09T12:53:25Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83777#p83777</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83776#p83776" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Хотя да, думаю, она может просто остановить приём данных после получения заголовков.</p></blockquote></div><p> Насколько помню, в этих случаях оно качает файл целиком. Если речь про гет запрос, без возможности сервера отдавать диапазонами.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2014-06-09T12:28:35Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83776#p83776</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83775#p83775" />
			<content type="html"><![CDATA[<p>Апдейт мессаджа не видел. .Значит всё таки по вашему как...</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2014-06-09T12:21:42Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83775#p83775</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83774#p83774" />
			<content type="html"><![CDATA[<p>Кажется с github любой файл, уточнить с телефона не могу.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2014-06-09T12:18:17Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83774#p83774</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83773#p83773" />
			<content type="html"><![CDATA[<p>Вопрос в том, как HttpQueryInfo получает эти заголовки. Как ещё, если не отправляя какой-то запрос? А если так, то что мешает сделать то же объектом HTTP? Запрос HEAD, как мы видим, не годится. Может, она использует GET так же, как я. Надо бы найти сервер без поддержки диапазонов и проверить на нём работу HttpQueryInfo. Иначе откуда уверенность, что она там сработает?</p><p>Хотя да, думаю, она может просто остановить приём данных после получения заголовков.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-06-09T11:24:58Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83773#p83773</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83772#p83772" />
			<content type="html"><![CDATA[<p>И в таком случае опять же пользовать HttpQueryInfo? Тогда уже смысл этого метода теряется.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2014-06-09T11:08:31Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83772#p83772</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83771#p83771" />
			<content type="html"><![CDATA[<p>Диапазон можно обозначать и от конца файла. Вот так последний байт можно скачать:<br /></p><div class="codebox"><pre><code>
HTTP.SetRequestHeader(&quot;Range&quot;, &quot;bytes=-1&quot;)
</code></pre></div><p>Если сервер не поддерживает диапазоны, то, как я понимаю, в свойстве Status должен быть код ошибки. Но размер файла в таком случае остаётся неизвестным. Вряд ли в заголовках он будет обозначен.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-06-09T10:15:08Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83771#p83771</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83770#p83770" />
			<content type="html"><![CDATA[<p><strong>YMP</strong><br />Чертовски любопытно!</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2014-06-09T09:11:30Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83770#p83770</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=83769#p83769" />
			<content type="html"><![CDATA[<p>Можно с помощью GET получить нужные заголовки, скачав 1 байт. Размер можно извлечь из Content-Range.<br /></p><div class="codebox"><pre><code>
url = https://docs.google.com/uc?export=download&amp;id=0B7FildjsrNkILWhYVHYwanJLS3c
HTTP := ComObjCreate(&quot;WinHTTP.WinHTTPRequest.5.1&quot;)
HTTP.Open(&quot;GET&quot;, url)
HTTP.SetRequestHeader(&quot;Range&quot;, &quot;bytes=0-0&quot;)
HTTP.Send()
MsgBox, % HTTP.GetAllResponseHeaders()
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2014-06-09T09:05:31Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=83769#p83769</id>
		</entry>
</feed>
