Timeout Issues with WinHTTPRequest5.1 (COM Object) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Timeout Issues with WinHTTPRequest5.1 (COM Object)

20 Feb 2019, 22:15

Hello,

I've tested this using my web browser, however when using WinHttp to retreive this information, it appears to "time out" and give up when the response takes "too long".

In my web browser (Chrome), it does take quite some time to retreive the result of this API request, possibly a whole minute. From my limited experience with using WinHttp in AHK, I've noticed that even when the URL given is a valid https:// URL, when it takes a significant time to load the web page in my browser (15-25+ seconds), WinHttp seems to give up before waiting long enough to get the results.

My question is: is there any way around this?? Can I tell this WinHttp to wait longer for the response (because I know there is a response coming)?

Here is my current code, any URL that takes a very long time to load should suffice for the URL variable here.

Code: Select all

try 
{ 
	URLaddress := "https://iprospectus.getstat.com/api/v2/26480a9sidfj3098sjaskdfg45hg5ea12e8589edc898/sites/all?format=json"

	whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") 


	;=======;		RETRIEVE WEB DOCUMENT		;=======;

		whr.Open("GET", URLaddress, true)
		whr.Send()
		whr.WaitForResponse()


	fileContents := whr.ResponseText	;	Save web document to variable
}
MsgBox % fileContents
I've looked in the >>MSDN docs for WinHttpRequest object<< to try and figure it out myself.

I tried using whr.WaitForResponse(-1), but that still did not make timeout infinite..

I also tried using the event whr.OnResponseFinished, but my programming skill is not high enough to know how to use Events yet (or so I think).

Any help is much appreciated. Also, if there is a better way to do this, then that would be awesome.... I tried using URLDownloadToFile and the file will not create (so I'm assuming the same issue is being encountered). Am I missing something??

When I take out the try command, I get this error:

---------------------------
STATjson2XL.ahk
---------------------------
Error: 0x8000000A - The data necessary to complete this operation is not yet available.
Source: WinHttp.WinHttpRequest
Description: The data necessary to complete this operation is not yet available.


HelpFile: (null)
HelpContext: 0

Specifically: ResponseText

Line#
233: URLaddress := "https://iprospectus.getstat.com/api/v2/26480a9sidfj3098sjaskdfg45hg5ea12e8589edc898/keywords/list?site_id=2671&start=1&results=5000&format=json"
235: whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
240: whr.Open("GET", URLaddress, true)
242: whr.Send()
243: whr.WaitForResponse()
246: {
---> 247: MsgBox,fileContents := whr.ResponseText
248: }
319: Return
333: {


Continue running the script?
---------------------------
Yes No
---------------------------


After I retreive the JSON data associated with this API Call, I will need to parse it quickly into Excel.. so will post another Q about that once I figure this one out.

Thanks so much for your help!!!!!!!!!!!
-TL
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Timeout Issues with WinHTTPRequest5.1 (COM Object)  Topic is solved

20 Feb 2019, 23:25

Woohoo with a little more digging I found out the answer to my problem. I needed to set the timeout parameters with
whr.SetTimeouts()

IWinHttpRequest::SetTimeouts method

Here is my working code:

Code: Select all

try 
{ 
	URLaddress := "https://iprospectus.getstat.com/api/v2/26480a9sidfj3098sjaskdfg45hg5ea12e8589edc898/sites/all?format=json"

	whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") 


	;=======;		RETRIEVE WEB DOCUMENT		;=======;
		whr.SetTimeouts(0,30000,30000,120000)
		whr.Open("GET", URLaddress, true)
		whr.Send()
		whr.WaitForResponse()


	fileContents := whr.ResponseText	;	Save web document to variable
}
MsgBox % fileContents
The first 3 parameters for the SetTimeouts method are the default (millisecond) values for ResolveTimeout, ConnectTimeout, and SendTimeout.

The last parameter is the one I needed to modify, which is ReceiveTimeout.

Yay! :superhappy:
Last edited by Tigerlily on 21 Feb 2019, 04:00, edited 1 time in total.
-TL
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Timeout Issues with WinHTTPRequest5.1 (COM Object)

20 Feb 2019, 23:57

When posting a new post, it says I have been blocked for autohotkey.com.... why is this????? so confused... :?
-TL
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: Timeout Issues with WinHTTPRequest5.1 (COM Object)

21 Feb 2019, 00:10

Tigerlily wrote:
20 Feb 2019, 23:57
When posting a new post, it says I have been blocked for autohotkey.com.... why is this????? so confused... :?
Overshooting anti-spam measures, I assume...
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Timeout Issues with WinHTTPRequest5.1 (COM Object)

21 Feb 2019, 00:39

gregster wrote:
21 Feb 2019, 00:10
Tigerlily wrote:
20 Feb 2019, 23:57
When posting a new post, it says I have been blocked for autohotkey.com.... why is this????? so confused... :?
Overshooting anti-spam measures, I assume...
I see.. Alas, my new post has been lost in the unretreivable history of my clipboard.. woops.. :facepalm:
-TL
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Timeout Issues with WinHTTPRequest5.1 (COM Object)

21 Feb 2019, 03:59

Okay this is getting annoying, I have been able to post here and there and on my own posts, but not on others. I know I didn't do anything crazy..

:angry face:
-TL

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, doodles333, jameswrightesq, sofista and 294 guests