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 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!!!!!!!!!!!