I'm trying to use winHTTPRequest (a com object) in Ruby. But I'm having a problem setting the value of a property.
Here's some VB code
Dim web
Const WinHttpRequestOption_EnableRedirects = 6
Set web = CreateObject("WinHttp.WinHttpRequest.5.1")
web.Option(WinHttpRequestOption_EnableRedirects) = False
The last line is what I'm trying to accomplish with Ruby.
Here's the Ruby code
require 'win32ole'
WinHttpRequestOption_EnableRedirects = 6
web = WIN32OLE.new("WinHttp.WinHttpRequest.5.1")
web.Option(WinHttpRequestOption_EnableRedirects)= false This line results in a sytax error.
The PickAxe book clains you can set and get properties using normal Ruby hash notation. But for the life of me I haven't been able to figure out just what that notation should look like.
web.Option(WinHttpRequestOption_EnableRedirects)= false
This line results in a sytax error.
The PickAxe book clains you can set and get properties using normal Ruby hash notation. But for the life of me I haven't been able to figure out just what that notation should look like.
The last line is what I'm trying to accomplish with Ruby.
Here's the Ruby code
require 'win32ole'
WinHttpRequestOption_EnableRedirects = 6
web = WIN32OLE.new("WinHttp.WinHttpRequest.5.1")
web.Option(WinHttpRequestOption_EnableRedirects)= false This line
results in a sytax error.
web.Option(WinHttpRequestOption_EnableRedirects)= false
This line results in a sytax error.
The PickAxe book clains you can set and get properties using normal Ruby hash notation. But for the life of me I haven't been able to figure out just what that notation should look like.
Thanks Pit, but that doesn't do it. I had tried that notation but I get
this
C:/RubyScripts/postFrostHTTP.rb:4:in `method_missing': Option (WIN32OLERuntimeError)
OLE error code:80020004 in <Unknown>
<No Description>
HRESULT error code:0x80020004
Parameter not found. from C:/RubyScripts/postFrostHTTP.rb:4
I don't have WinHttp on this machine so I can't check this.
C:/RubyScripts/postFrostHTTP.rb:4:in `method_missing': Option
(WIN32OLERuntimeError)
OLE error code:80020004 in <Unknown>
<No Description>
HRESULT error code:0x80020004
Parameter not found. from C:/RubyScripts/postFrostHTTP.rb:4
(( web.Option[6] = false ))
If WIN32OLE is using the hash notation to access attributes,
there would be a problem with a method called '6' (illegal).
You could try examining the Option object with something like:
web.Option.each { |opt| p opt } # might not have an 'each' method
Use Ruby's "introspection" to nosey around and see what's available:
# may be useful to quote on this newsgroup
p web.Option.class
puts '=========='
puts((web.Option.methods - Object.methods).sort)
puts '=========='
puts((web.methods - Object.methods).sort)
puts '=========='
# If (e.g.) 'ole_methods' is in the list
puts web.ole_methods
I'm fairly confident with Ruby but I always have to mess around
trying different hacks with COM objects. Someone who uses them
twice a year is in much the same position as a COM newbie.
I don't have WinHttp on this machine so I can't check this.
C:/RubyScripts/postFrostHTTP.rb:4:in `method_missing': Option
(WIN32OLERuntimeError)
OLE error code:80020004 in <Unknown>
<No Description>
HRESULT error code:0x80020004
Parameter not found. from C:/RubyScripts/postFrostHTTP.rb:4
(( web.Option[6] = false ))
If WIN32OLE is using the hash notation to access attributes,
there would be a problem with a method called '6' (illegal).
You could try examining the Option object with something like:
web.Option.each { |opt| p opt } # might not have an 'each' method
Use Ruby's "introspection" to nosey around and see what's available:
# may be useful to quote on this newsgroup
p web.Option.class
puts '=========='
puts((web.Option.methods - Object.methods).sort)
puts '=========='
puts((web.methods - Object.methods).sort)
puts '=========='
# If (e.g.) 'ole_methods' is in the list
puts web.ole_methods
I'm fairly confident with Ruby but I always have to mess around
trying different hacks with COM objects. Someone who uses them
twice a year is in much the same position as a COM newbie.
daz
Thanks for the hint. ran into a few problems
web.Option.each failed
web.Option.methods doesn't exist
changed to puts((web.methods - Object.methods).sort)
this yielded the following list