Unexpected behavior when attempting to set WinHttp.WinHttpRequest.5.1 options Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
micasa
Posts: 24
Joined: 29 Dec 2018, 04:21

Unexpected behavior when attempting to set WinHttp.WinHttpRequest.5.1 options

05 Feb 2019, 10:02

Hello, everyone.

I am new to AHK, in general, so this might not be a bug at all, but the behavior seems a bit unexpected to me.

WinHttp.WinHttpRequest.5.1 provides various options that can be set. Here is the reference:

https://docs.microsoft.com/en-us/windows/desktop/winhttp/winhttprequestoption

In AHK V1, it is possible to set WinHttp.WinHttpRequest.5.1 options using variable assignment.

For example we can disable automatic redirects like this:

Code: Select all

HttpObj.Option(6) := False
However, when I try to run this code in AHK V2, it throws an error:

Code: Select all

Error: Invalid assignment.

Specifically: := False
I have tried various ways to change this option, including

Code: Select all

HttpObj.Option(6) := False
HttpObj.Option(6) := "False"
HttpObj.Option(6) := 0
HttpObj.Option(6, False)
HttpObj.Option(6, "False")
HttpObj.Option(6, 0)
I even tried some combinations based on the C++ typedef, but nothing seems to work.

Does anyone know how to set these options in AHK V2? If yes, please let me know.

Thank you for your valuable time.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Unexpected behavior when attempting to set WinHttp.WinHttpRequest.5.1 options  Topic is solved

05 Feb 2019, 10:18

You need to use [] instead of (). The () were allowed for no good reason and are actually wrong.
Recommends AHK Studio
micasa
Posts: 24
Joined: 29 Dec 2018, 04:21

Re: Unexpected behavior when attempting to set WinHttp.WinHttpRequest.5.1 options

05 Feb 2019, 10:23

nnnik wrote:
05 Feb 2019, 10:18
You need to use [] instead of (). The () were allowed for no good reason and are actually wrong.
Thank you very much! Actually, I was thinking that, but when I tried some array methods on HttpObj.Option I was getting errors, so I wrongly assumed [] would not work.

Thanks again for your help and quick reply!
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Unexpected behavior when attempting to set WinHttp.WinHttpRequest.5.1 options

01 Mar 2019, 09:51

nnnik wrote:
05 Feb 2019, 10:18
You need to use [] instead of (). The () were allowed for no good reason and are actually wrong.
Just curious why () is wrong in this instance and why [] is right? I'm wanting to make the switch to 2.0, but learning more about it before fully jumping over as I have long scripts written in AHK 1.1+ that I use for work. I see in the MSDN docs that in C++ it is written using (). Where would I be able to go to (other than the AHK forums) to find this important information?

Also, WinHttpRequest5.1 seems to be somewhat inconsistent soemtimes with the data it returns I've noticed..
-TL
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Unexpected behavior when attempting to set WinHttp.WinHttpRequest.5.1 options

01 Mar 2019, 11:09

[] is an array access operator - . works similar:

Code: Select all

obj["key"] ;or
obj.key
() is used to call functions and methods:

Code: Select all

obj.method() ;calls the method "method" inside obj
function()
These 2 things are not the same thing and logically it doesn't make sense in AHK that you assign something to the result of a function so:

Code: Select all

function("key") := "somevalue"
has no meaning just as

Code: Select all

obj.method("key") := "somevalue"
has no meaning either.

The reason as to why this was possible in v1 is unknown to me.
I vaguely remember hearing or reading a comment in this forum or the source that it had something to do with compatability to another language, but Im honestly not sure.
Recommends AHK Studio
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Unexpected behavior when attempting to set WinHttp.WinHttpRequest.5.1 options

04 Mar 2019, 04:00

Oh I see - thanks for the explanation nnnik. Very much appreciated :D
-TL

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Albireo, coder96, kunkel321, ntepa, Pyper, w_i_k_i_d, wilkster and 48 guests