<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Надёжное скачивание изображения]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=15898</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15898&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Надёжное скачивание изображения».]]></description>
		<lastBuildDate>Tue, 08 Dec 2020 09:41:42 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[AHK: Надёжное скачивание изображения]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=144001#p144001</link>
			<description><![CDATA[<p>Есть задача надёжно качать картинку — задействовать условие, чтобы скачивание происходило только когда изображение действительно доступно. В реальном примере ссылка на изображение бывает активна только по определенным условиям (логин, включение доступа и тп), хотя наверно это относится и к любым изображениям. То есть, как скачивать с учётом разрывов соединений, сбросов логина — только когда известно, что это картинка?</p><br /><div class="codebox"><pre><code>
HTTP := ComObjCreate(&quot;WinHTTP.WinHTTPRequest.5.1&quot;)
User_Agent := &quot;Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36&quot;

   loop  ;CONNECT_LOOP
   {     ;CONNECT_LOOP
      HTTP.Open(&quot;GET&quot;, URL, true)
      HTTP.SetRequestHeader(&quot;Referer&quot;, URL)
      ;HTTP.SetRequestHeader(&quot;Cookie&quot;, cookies)
      ;HTTP.SetRequestHeader(&quot;Cookie2&quot;, &quot;$Version=1&quot;)
      HTTP.SetRequestHeader(&quot;Accept-Language&quot;, &quot;ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7&quot;)
      HTTP.SetRequestHeader(&quot;User-Agent&quot;, User_Agent)
      HTTP.SetRequestHeader(&quot;Pragma&quot;, &quot;no-cache&quot;)
      HTTP.SetRequestHeader(&quot;If-Modified-Since&quot;, &quot;Sat, 1 Jan 2000 00:00:00 GMT&quot;)

      try {
         HTTP.Send()
         HTTP.WaitForResponse()
         ;!!MsgBox, % HTTP.StatusText 
         ResponseHeaders := HTTP.getAllResponseHeaders()
         Body := HTTP.ResponseBody
/*
         status := HTTP.status
         if status in 404
            break
*/
         If InStr(ResponseHeaders, &quot;Content-Type:&quot;) and not InStr(ResponseHeaders, &quot;image/jpeg&quot;)
            break
         pData := NumGet(ComObjValue(Body), A_PtrSize = 8? 16:12, &quot;ptr&quot;)
         File := FileOpen(A_ScriptDir &quot;\&quot; page_code &quot;\&quot; ren, &quot;w&quot;)
         File.RawWrite(pData + 0, Body.MaxIndex() + 1)

         break
      }
      catch {
         Sleep, 5000
      }
   }     ;CONNECT_LOOP
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Tue, 08 Dec 2020 09:41:42 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=144001#p144001</guid>
		</item>
	</channel>
</rss>
