Sign in to follow this  
Followers 0
CatchFish

3 Things That AutoIt3 Can't Do

7 posts in this topic

I create an instance of WinHttpRequest:

$oWinHttp = ObjCreate("WinHttp.WinHttpRequest.5.1")

Then there are 3 things that AutoIt3 can't do:

1. onreadystatechange...

I want to set the onreadystatechange property which must be assigned the handle of a custom function. The problem is, there is no way to get a handle of a function, nor any special syntax support in AutoIt3. Therefore it is impossible to set a proper value for it. But in Javascript or VBScript I can do it in this way:

oWinHttp.onreadystatechange = somefunction; //Javascript way

oWinHttp.onreadystatechange = GetRef("SomeFunction") 'VBScript way

2. Write to option()

option() is a read/write property. I need to set the URL codepage to 936 (meaning gb2312), so I do this:

Dim $WinHttpRequestOption_URLCodePage = 2 ;Code page
$oWinHttp.open("GET", "http://www.google.com", false)
$oWinHttp.option($WinHttpRequestOption_URLCodePage) = "936"
$oWinHttp.send()

Then I use ConsoleWrite() to view the value of $oWinHttp.option($WinHttpRequestOption_URLCodePage). The result is 65001 (meaning utf-8), same as the original, because AutoIt3 doesn't seem to support Object.Property(Item) = Value syntax which is widely used in Javascript and VBScript.

3. responseBody...

When $oWinHttp.send() successfully returns, $oWinHttp.responseBody should be an array of unsigned interger which contains raw data of the source. I need the raw data instead of $oWinHttp.responseText because I need to do some codepage transformation. I try to use the following code:

Dim $oStream, $Result
$oStream = ObjCreate("ADODB.Stream")
$oStream.Type = 1
$oStream.Mode = 3
$oStream.Open
$oStream.Write($oWinHttp.responseBody)
$oStream.Position = 0
$oStream.Type = 2
$oStream.Charset = "gb2312"
$Result = $oStream.ReadText()

But the $Result is empty. I find that AutoIt3 doesn't support arrays like ResponseBody. Compared to the similar code in VBScript, everything works fine.

Any ideas?

Share this post


Link to post
Share on other sites



Has anyone resolved the ResponseBody issue?

-OR-

A fix for InetGet() so that it works under Vista?

Share this post


Link to post
Share on other sites

Needing help on this too.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Edits inline *:

1) you certainly CAN do this with ObjEvent()

2) there was a discussion about this involving the dictionary object a while back and it was resolved - can't find the thread at the moment. In any case, are you sure you want to pass a string into that option?

* Looking at the code page values here http://msdn2.microsoft.com/en-us/library/ms776446.aspx would you want to pass 0x936 ?

** Update2: looks like the codepage value is base10 rather than Hex, so use 936 (instead of "936" or 0x936)

Examine the option and you will see that you are in fact affecting a change:

$oWinHttp.open("GET", "http://www.google.com", false)
ConsoleWrite($oWinHttp.option($WinHttpRequestOption_URLCodePage) & @CR)
$oWinHttp.option($WinHttpRequestOption_URLCodePage) = 936
ConsoleWrite($oWinHttp.option($WinHttpRequestOption_URLCodePage) & @CR)

3) if I remember correctly, this returns a "safeArray"... I have not found a way of dealing with this in AutoIt either - the IE .Navigate2 method uses this as well as many others

* Looking at the msdn docs, it just says of responseBody "This property returns the response data in an array of unsigned bytes. If the response does not have a response body, an empty variant is returned."

I looked into this out of curiosity a long time ago and quit when I got this far and saw that the response was empty.

I would suggest that you create a working VBScript example with your best shot at AutoIt conversion... post it back here for discussion and then it may result in a feature request or bug report.

Dale

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Previous reply updated...


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Edits inline *:

1) you certainly CAN do this with ObjEvent()

2) there was a discussion about this involving the dictionary object a while back and it was resolved - can't find the thread at the moment. In any case, are you sure you want to pass a string into that option?

* Looking at the code page values here http://msdn2.microsoft.com/en-us/library/ms776446.aspx would you want to pass 0x936 ?

** Update2: looks like the codepage value is base10 rather than Hex, so use 936 (instead of "936" or 0x936)

Examine the option and you will see that you are in fact affecting a change:

$oWinHttp.open("GET", "http://www.google.com", false)
ConsoleWrite($oWinHttp.option($WinHttpRequestOption_URLCodePage) & @CR)
$oWinHttp.option($WinHttpRequestOption_URLCodePage) = 936
ConsoleWrite($oWinHttp.option($WinHttpRequestOption_URLCodePage) & @CR)

3) if I remember correctly, this returns a "safeArray"... I have not found a way of dealing with this in AutoIt either - the IE .Navigate2 method uses this as well as many others

* Looking at the msdn docs, it just says of responseBody "This property returns the response data in an array of unsigned bytes. If the response does not have a response body, an empty variant is returned."

I looked into this out of curiosity a long time ago and quit when I got this far and saw that the response was empty.

I would suggest that you create a working VBScript example with your best shot at AutoIt conversion... post it back here for discussion and then it may result in a feature request or bug report.

Dale

Thanks for the post and answers.

ADODB.Stream method works for me. ( Windows 7 64bit )

But I prefer the BinarytoString Method.

; change flag if ResponseBody use other encoding
$sHtml = BinaryToString($oHTTP.ResponseBody, 1)

BTW: I found winhttp is always faster than inetread(autoit 3.3.8), any idea?

Share this post


Link to post
Share on other sites

You shouldn't necro a thread 4.5 years old.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0