win32ole help

  • Thread starter Ernest Ellingson
  • Start date
E

Ernest Ellingson

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
 
P

Pit Capitain

Ernest said:
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
 
E

Ernest Ellingson

Pit said:
Ernest said:
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
 
D

daz

Ernest said:
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
 
E

Ernest Ellingson

daz said:
Ernest said:
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
 
M

Masaki Suketa

Hello.
In message "win32ole help"
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top