Win32ole help

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.

Does anyone have a clue?

Ernie

Ernest Ellingson schrieb:

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.

Hash notation would be

   web.Option[ WinHttpRequestOption_EnableRedirects ] = false

Regards,
Pit

Hello.

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.

Try the setproperty method.

require 'win32ole'
WinHttpRequestOption_EnableRedirects = 6
web = WIN32OLE.new("WinHttp.WinHttpRequest.5.1")
web.setproperty('Option', WinHttpRequestOption_EnableRedirects, false)

Regards,

  Masaki Suketa

···

In message "win32ole help" on 05/07/07, Ernest Ellingson <erne@powernav.com.remove.this> writes:

Pit Capitain wrote:

Ernest Ellingson schrieb:

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.

Hash notation would be

  web.Option[ WinHttpRequestOption_EnableRedirects ] = false

Regards,
Pit

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

Ernie

Ernest Ellingson wrote:

require 'win32ole'
WinHttpRequestOption_EnableRedirects = 6
web = WIN32OLE.new("WinHttp.WinHttpRequest.5.1")
web.Option(WinHttpRequestOption_EnableRedirects)= false # syntax error

EDIT (was same reply as Pit gave)

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

daz wrote:

Ernest Ellingson wrote:

require 'win32ole'
WinHttpRequestOption_EnableRedirects = 6
web = WIN32OLE.new("WinHttp.WinHttpRequest.5.1")
web.Option(WinHttpRequestOption_EnableRedirects)= false # syntax error

EDIT (was same reply as Pit gave)

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

=
_getproperty
_invoke
_setproperty
each
invoke
method_missing
ole_free
ole_func_methods
ole_get_methods
ole_method
ole_method_help
ole_methods
ole_obj_help
ole_put_methods
setproperty

Expeimented with the setproperty method

I used web.setproperty('Option', WinHttpRequestOption_EnableRedirects, false)

That did the trick.

Thanks again

Ernie