<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=16327&amp;type=atom" />
	<updated>2021-05-08T14:08:19Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=16327</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147747#p147747" />
			<content type="html"><![CDATA[<p>Когда OnResponseDataAvailable() вызывается в первый раз (блок <em>if Info.start</em>), length — это полный размер данных, потом оставшийся.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-08T14:08:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147747#p147747</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147746#p147746" />
			<content type="html"><![CDATA[<p>То есть по сути можно сделать отображения процесса скачивания файла?<br />И как тогда получить сколько из скольких скачано?</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-05-08T12:52:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147746#p147746</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147742#p147742" />
			<content type="html"><![CDATA[<p>Перед процессом скачивания и во время его, когда объект получает информацию о том, что есть (или ещё есть) данные для загрузки.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-08T03:46:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147742#p147742</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147741#p147741" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>На самом деле, WinHttpRequest тоже <a href="https://docs.microsoft.com/en-us/windows/win32/winhttp/iwinhttprequestevents-interface">может</a>.</p></blockquote></div><p>The OnResponseDataAvailable event occurs when data is available from the response.<br />Что именно это значит? Вызовется ли оно, когда мы допустим пытаемся скачать файл и идет процесс скачки? Или же оно вызывается когда весь файл станет доступным?</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-05-08T03:30:50Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147741#p147741</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147740#p147740" />
			<content type="html"><![CDATA[<p>Как-то так:<br /></p><div class="codebox"><pre><code>#Persistent
url := &quot;https://www.autohotkey.com/assets/images/ahk-logo-no-text241x78-180.png&quot;

Whr := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
Events := new IWinHttpRequestEvents(Whr, Func(&quot;MyFunc&quot;))
Whr.Open(&quot;GET&quot;, url, true)
Whr.Send()

MyFunc(info, data) {
   if (info = &quot;error&quot;)
      MsgBox,, Error, % &quot;Number: &quot; . data.number . &quot;`nDescription: &quot; . data.desc
   else if (info + 0) {
      File := FileOpen(&quot;ahk.png&quot;, &quot;w&quot;)
      File.RawWrite(data + 0, info)
      File.Close()
      MsgBox, 64,, Data received, .5
   }
}

class IWinHttpRequestEvents
{ ; https://docs.microsoft.com/en-us/windows/win32/winhttp/iwinhttprequestevents-interface
   __New(Whr, UserFunc) {
      this.UserFunc := UserFunc
      this._CreateInterface()
      this._ConnectInterface(Whr)
   }
      
   Status[] {
      get {
         Return this.Info.status
      }
   }
   
   _CreateInterface() {
      static Methods := [ {name: &quot;QueryInterface&quot;         , paramCount: 3}
                        , {name: &quot;AddRef&quot;                 , paramCount: 1}
                        , {name: &quot;Release&quot;                , paramCount: 1}
                        , {name: &quot;OnResponseStart&quot;        , paramCount: 3}
                        , {name: &quot;OnResponseDataAvailable&quot;, paramCount: 2}
                        , {name: &quot;OnResponseFinished&quot;     , paramCount: 1}
                        , {name: &quot;OnError&quot;                , paramCount: 3} ]
                        
      this.SetCapacity(&quot;vtable&quot;, len := A_PtrSize*(Methods.Count() + 1))
      pVtable := this.GetAddress(&quot;vtable&quot;)
      this.SetCapacity(&quot;IUnknown&quot;, A_PtrSize)
      NumPut(pVtable, this.GetAddress(&quot;IUnknown&quot;))
      
      this.Info := {refOffset: A_PtrSize * Methods.Count(), UserFunc: this.UserFunc}
      this.EventInst := new this.Events(this.Info)
      this.Callbacks := []
      for k, v in Methods {
         Callback := new BoundFuncCallback( ObjBindMethod(this.EventInst, v.name), v.paramCount, &quot;Fast&quot; )
         NumPut(Callback.addr, pVtable + A_PtrSize*(k - 1))
         this.Callbacks.Push(Callback)
      }
      NumPut(0, this.Info.refOffset)
   }
   
   _ConnectInterface(Whr) {
   ; IConnectionPointContainer, IConnectionPoint — OCIdl.h
   ; IWinHttpRequestEvents — httprequest.idl
      static IID_IConnectionPointContainer := &quot;{B196B284-BAB4-101A-B69C-00AA00341D07}&quot;
           , IID_IWinHttpRequestEvents     := &quot;{F97F4E15-B787-4212-80D1-D380CBBF982E}&quot;
           
      pICPC := pIConnectionPointContainer := ComObjQuery(Whr, IID_IConnectionPointContainer)
      riid := CLSIDFromString(IID_IWinHttpRequestEvents, _)
      
      ; IConnectionPointContainer::FindConnectionPoint
      DllCall(NumGet(NumGet(pICPC + 0) + A_PtrSize*4), &quot;Ptr&quot;, pICPC, &quot;Ptr&quot;, riid, &quot;PtrP&quot;, pIConnectionPoint)
      ObjRelease(pICPC), pICP := pIConnectionPoint
      
      ; IConnectionPoint::Advise
      DllCall(NumGet(NumGet(pICP + 0) + A_PtrSize*5), &quot;Ptr&quot;, pICP, &quot;Ptr&quot;, this.GetAddress(&quot;IUnknown&quot;), &quot;UIntP&quot;, cookie)
      this.pICP := pICP, this.cookie := cookie
   }
   
   __Delete() {
      ; IConnectionPoint::Unadvise
      DllCall(NumGet(NumGet(this.pICP + 0) + A_PtrSize*6), &quot;Ptr&quot;, this.pICP, &quot;UInt&quot;, this.cookie)
      ObjRelease(this.pICP)
      this.Delete(&quot;Callbacks&quot;)
      this.SetCapacity(&quot;vtable&quot;, 0), this.Delete(&quot;vtable&quot;)
      this.Delete(&quot;EventInst&quot;)
   }
   
   class Events {
      __New(Info) {
         this.Info := Info
      }
      
      QueryInterface(pIWinHttpRequestEvents, riid, ppvObject) {
         static IID_IUnknown              := &quot;{00000000-0000-0000-C000-000000000046}&quot;
              , IID_IWinHttpRequestEvents := &quot;{F97F4E15-B787-4212-80D1-D380CBBF982E}&quot;
              , E_NOINTERFACE := 0x80004002, S_OK := 0, _, __
              , p1 := CLSIDFromString(IID_IUnknown             ,  _)
              , p2 := CLSIDFromString(IID_IWinHttpRequestEvents, __)
              
         if !( DllCall(&quot;Ole32\IsEqualGUID&quot;, &quot;Ptr&quot;, riid, &quot;Ptr&quot;, p1)
            || DllCall(&quot;Ole32\IsEqualGUID&quot;, &quot;Ptr&quot;, riid, &quot;Ptr&quot;, p2) )
         { ; if riid doesn&#039;t match IID_IUnknown nor IID_IWinHttpRequestEvents
            NumPut(0, ppvObject + 0)
            Return E_NOINTERFACE
         }
         else {
            NumPut(pIWinHttpRequestEvents, ppvObject + 0)
            DllCall(NumGet(NumGet(ppvObject + 0) + A_PtrSize), &quot;Ptr&quot;, ppvObject)
            Return S_OK
         }
      }
      
      AddRef(pIWinHttpRequestEvents) {
         refOffset := pIWinHttpRequestEvents + this.Info.refOffset
         NumPut(refCount := NumGet(refOffset + 0, &quot;UInt&quot;) + 1, refOffset, &quot;UInt&quot;)
         Return refCount
      }
      
      Release(pIWinHttpRequestEvents) {
         refOffset := pIWinHttpRequestEvents + this.Info.refOffset
         NumPut(refCount := NumGet(refOffset + 0, &quot;UInt&quot;) - 1, refOffset, &quot;UInt&quot;)
         Return refCount
      }
      
      OnResponseStart(pIWinHttpRequestEvents, status, pType) {
         ; type := StrGet(pType)
         this.Info.status := status
         this.Info.start := true
      }
      
      OnResponseDataAvailable(pIWinHttpRequestEvents, ppSafeArray) {
         Critical
         Info := this.Info
         pSafeArray := NumGet(ppSafeArray + 0)
         pData := NumGet(pSafeArray + 8 + A_PtrSize)
         length := NumGet(pSafeArray + 8 + A_PtrSize*2, &quot;UInt&quot;)
         if Info.start {
            Info.start := false
            this.SetCapacity(&quot;Data&quot;, 0)
            this.SetCapacity(&quot;Data&quot;, Info.length := length)
            DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;, this.GetAddress(&quot;Data&quot;), &quot;Ptr&quot;, pData, &quot;Ptr&quot;, length)
         }
         else {
            this.SetCapacity(&quot;Data&quot;, Info.length + length)
            DllCall(&quot;RtlMoveMemory&quot;, &quot;Ptr&quot;, this.GetAddress(&quot;Data&quot;) + Info.length, &quot;Ptr&quot;, pData, &quot;Ptr&quot;, length)
            Info.length += length
         }
      }
      
      OnResponseFinished(pIWinHttpRequestEvents) {
         this.Info.UserFunc.Call(this.Info.length, this.GetAddress(&quot;Data&quot;))
         this.SetCapacity(&quot;Data&quot;, 0)
      }
      
      OnError(pIWinHttpRequestEvents, errorNumber, pErrorDescription) {
         this.SetCapacity(&quot;Data&quot;, 0)
         this.Info.UserFunc.Call(&quot;error&quot;, { number: errorNumber, desc: StrGet(pErrorDescription) })
      }
   }
}

class BoundFuncCallback
{
   __New(BoundFuncObj, paramCount, options := &quot;&quot;) {
      this.pInfo := Object( {BoundObj: BoundFuncObj, paramCount: paramCount} )
      this.addr := RegisterCallback(this.__Class . &quot;._Callback&quot;, options, paramCount, this.pInfo)
   }
   __Delete() {
      ObjRelease(this.pInfo)
      DllCall(&quot;GlobalFree&quot;, &quot;Ptr&quot;, this.addr, &quot;Ptr&quot;)
   }
   _Callback(Params*) {
      Info := Object(A_EventInfo), Args := []
      Loop % Info.paramCount
         Args.Push( NumGet(Params + A_PtrSize*(A_Index - 2)) )
      Return Info.BoundObj.Call(Args*)
   }
}

CLSIDFromString(IID, ByRef CLSID) {
   VarSetCapacity(CLSID, 16, 0)
   if res := DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;WStr&quot;, IID, &quot;Ptr&quot;, &amp;CLSID, &quot;UInt&quot;)
      throw Exception(&quot;CLSIDFromString failed. Error: &quot; . Format(&quot;{:#x}&quot;, res))
   Return &amp;CLSID
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-07T21:06:26Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147740#p147740</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147739#p147739" />
			<content type="html"><![CDATA[<p>Для 32 бит.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-07T20:29:25Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147739#p147739</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147738#p147738" />
			<content type="html"><![CDATA[<p>Да. <strong>infogulch</strong> даже враппер написал.<br />Но надо тестировать - я этим не занимался.<br /><a href="https://github.com/infogulch/AsyncHttp/blob/master/AsyncHttp.ahk">https://github.com/infogulch/AsyncHttp/ … ncHttp.ahk</a><br /><a href="https://github.com/infogulch/WinHttpRequest/blob/master/WinHttpRequest.ahk">https://github.com/infogulch/WinHttpReq … equest.ahk</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2021-05-07T20:27:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147738#p147738</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147737#p147737" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>возникла с &quot;мультипоточным&quot; запросом.</p></blockquote></div><div class="quotebox"><cite>lexikos пишет:</cite><blockquote><p>Unlike WinHttpRequest, it can notify us when the request is complete.</p></blockquote></div><p>На самом деле, WinHttpRequest тоже <a href="https://docs.microsoft.com/en-us/windows/win32/winhttp/iwinhttprequestevents-interface">может</a>.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-07T19:26:37Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147737#p147737</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147736#p147736" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>можете назвать еще как-то ограничения с данным объектом?</p></blockquote></div><p><a href="https://www.autohotkey.com/boards/viewtopic.php?t=9554">https://www.autohotkey.com/boards/viewtopic.php?t=9554</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2021-05-07T18:36:26Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147736#p147736</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147730#p147730" />
			<content type="html"><![CDATA[<p>Не знаю.. Просто скрыть юзер агента..</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-05-07T14:46:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147730#p147730</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147729#p147729" />
			<content type="html"><![CDATA[<p>А какой смысл указывать пробел?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-07T14:01:48Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147729#p147729</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147723#p147723" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>Referer для Msxml2.XMLHTTP указать невозможно.</p></blockquote></div><p>Спасибо за информацию, а где можно по этому поводу информацию найти? И если не сложно, можете назвать еще как-то ограничения с данным объектом?<br /></p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>А должен? Там вообще-то формат определённый есть.</p></blockquote></div><p>Да вот и не знаю должен или нет, просто почему-то для одного объекта если указать объект - сервер просто ставит прочерк, а если для второго объекта, то пишется стандартный юзер агент от этого объекта.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-05-07T12:55:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147723#p147723</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147720#p147720" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>Для одного метода работало, для второго нет.</p></blockquote></div><p>Это не методы, а объекты.<br />Referer для Msxml2.XMLHTTP указать невозможно.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2021-05-07T08:25:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147720#p147720</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147719#p147719" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>не применяется User-Agent, если указать значение - пробел</p></blockquote></div><p>А должен? Там вообще-то формат определённый есть.</p><div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>Потом для второго метода не работал хеадер referer.</p></blockquote></div><p>Попробуйте без класса, может там где-то косяк.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-07T08:12:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147719#p147719</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Не применяется SetRequestHeader в Msxml2.XMLHTTP]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147718#p147718" />
			<content type="html"><![CDATA[<p>Сначала был вопрос в том, что не применяется User-Agent, если указать значение - пробел. Для одного метода работало, для второго нет.<br />Потом для второго метода не работал хеадер referer.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-05-07T07:12:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147718#p147718</id>
		</entry>
</feed>
