<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=9592</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=9592&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.».]]></description>
		<lastBuildDate>Sat, 29 Sep 2018 23:46:34 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=128944#p128944</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sat, 29 Sep 2018 23:46:34 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=128944#p128944</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=128828#p128828</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 23 Sep 2018 19:58:52 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=128828#p128828</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=128822#p128822</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sat, 22 Sep 2018 22:48:03 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=128822#p128822</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83780#p83780</link>
			<description><![CDATA[<p>Разбираемся, как что работает, какие есть возможности.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Mon, 09 Jun 2014 14:02:45 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83780#p83780</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83779#p83779</link>
			<description><![CDATA[<p>Да всем устраивает, просто рассуждения о более коротком коде.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 09 Jun 2014 13:46:31 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83779#p83779</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83778#p83778</link>
			<description><![CDATA[<p>А чем HttpQueryInfo не устраивает?<br />В чем его минусы?</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Mon, 09 Jun 2014 12:57:04 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83778#p83778</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83777#p83777</link>
			<description><![CDATA[<div class="quotebox"><blockquote><p>Насколько помню, в этих случаях оно качает файл целиком. Если речь про гет запрос, без возможности сервера отдавать диапазонами.</p></blockquote></div><p>HttpQueryInfo вполне может и не качать. Как только скачались заголовки, функция может прекратить приём данных, т.к. ей больше ничего не нужно.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Mon, 09 Jun 2014 12:53:25 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83777#p83777</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83776#p83776</link>
			<description><![CDATA[<div class="quotebox"><blockquote><p>Хотя да, думаю, она может просто остановить приём данных после получения заголовков.</p></blockquote></div><p> Насколько помню, в этих случаях оно качает файл целиком. Если речь про гет запрос, без возможности сервера отдавать диапазонами.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 09 Jun 2014 12:28:35 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83776#p83776</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83775#p83775</link>
			<description><![CDATA[<p>Апдейт мессаджа не видел. .Значит всё таки по вашему как...</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 09 Jun 2014 12:21:42 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83775#p83775</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83774#p83774</link>
			<description><![CDATA[<p>Кажется с github любой файл, уточнить с телефона не могу.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 09 Jun 2014 12:18:17 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83774#p83774</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83773#p83773</link>
			<description><![CDATA[<p>Вопрос в том, как HttpQueryInfo получает эти заголовки. Как ещё, если не отправляя какой-то запрос? А если так, то что мешает сделать то же объектом HTTP? Запрос HEAD, как мы видим, не годится. Может, она использует GET так же, как я. Надо бы найти сервер без поддержки диапазонов и проверить на нём работу HttpQueryInfo. Иначе откуда уверенность, что она там сработает?</p><p>Хотя да, думаю, она может просто остановить приём данных после получения заголовков.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Mon, 09 Jun 2014 11:24:58 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83773#p83773</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83772#p83772</link>
			<description><![CDATA[<p>И в таком случае опять же пользовать HttpQueryInfo? Тогда уже смысл этого метода теряется.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 09 Jun 2014 11:08:31 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83772#p83772</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83771#p83771</link>
			<description><![CDATA[<p>Диапазон можно обозначать и от конца файла. Вот так последний байт можно скачать:<br /></p><div class="codebox"><pre><code>
HTTP.SetRequestHeader(&quot;Range&quot;, &quot;bytes=-1&quot;)
</code></pre></div><p>Если сервер не поддерживает диапазоны, то, как я понимаю, в свойстве Status должен быть код ошибки. Но размер файла в таком случае остаётся неизвестным. Вряд ли в заголовках он будет обозначен.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Mon, 09 Jun 2014 10:15:08 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83771#p83771</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83770#p83770</link>
			<description><![CDATA[<p><strong>YMP</strong><br />Чертовски любопытно!</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Mon, 09 Jun 2014 09:11:30 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83770#p83770</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: UrlDownloadToFile с таким же расширением, как и скачиваемый файл.]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=83769#p83769</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Mon, 09 Jun 2014 09:05:31 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=83769#p83769</guid>
		</item>
	</channel>
</rss>
