Adding Post Data to IE.navigate method with Ruby

B

Bach Le

Hi all,

I'm automating IE with Watir and Ruby and I have a slight problem that
I can't seem to solve. I'd like to pass post data to IE's navigate
method (http://msdn2.microsoft.com/en-us/library/aa752093.aspx)

Seems like the postdata parameter is a byte array so here's what I've
done in ruby to try to pass this data

bytearray = []
postdata.each_byte{ |c| bytearray.push(c) }
@ie.navigate(url, nil, nil, bytearray, "Content-Type:
application/x-www-form-urlencoded\r\n")

Fiddler seems to always say that the content length is 16 times longer
than the actual length and I'm not sure why. Does anyone know how make
this call work? TIA.

-Bach
 
P

Paul Rogers

Hi all,

I'm automating IE with Watir and Ruby and I have a slight problem that
I can't seem to solve. I'd like to pass post data to IE's navigate
method (http://msdn2.microsoft.com/en-us/library/aa752093.aspx)

Seems like the postdata parameter is a byte array so here's what I've
done in ruby to try to pass this data

bytearray = []
postdata.each_byte{ |c| bytearray.push(c) }
@ie.navigate(url, nil, nil, bytearray, "Content-Type:
application/x-www-form-urlencoded\r\n")

Fiddler seems to always say that the content length is 16 times longer
than the actual length and I'm not sure why. Does anyone know how make
this call work? TIA.

-Bach

post data is usually hash like, so maybe this is what you need
( untested )
data = {}
data["name"]=>'paul'
data["url"]=> 'www.google.com'

post_data = []
data.each_pair do |k,v|
post_data << "#{k}=#{v}"
end
@ie.navigate(url, nil, nil, post_data.join("&"), "Content-Type:
application/x-www-form-urlencoded\r\n")

You'll probably have to url encode the data too though

Paul
 
B

Bach Le

I'm automating IE with Watir and Ruby and I have a slight problem that
I can't seem to solve. I'd like to pass post data to IE's navigate
method (http://msdn2.microsoft.com/en-us/library/aa752093.aspx)
Seems like the postdata parameter is a byte array so here's what I've
done in ruby to try to pass this data
bytearray = []
postdata.each_byte{ |c| bytearray.push(c) }
@ie.navigate(url, nil, nil, bytearray, "Content-Type:
application/x-www-form-urlencoded\r\n")
Fiddler seems to always say that the content length is 16 times longer
than the actual length and I'm not sure why. Does anyone know how make
this call work? TIA.

post data is usually hash like, so maybe this is what you need
( untested )
data = {}
data["name"]=>'paul'
data["url"]=> 'www.google.com'

post_data = []
data.each_pair do |k,v|
post_data << "#{k}=#{v}"
end
@ie.navigate(url, nil, nil, post_data.join("&"), "Content-Type:
application/x-www-form-urlencoded\r\n")

You'll probably have to url encode the data too though

Paul

Hi Paul,

Thanks for getting back to me. Seems like IE won't do a POST unless
that parameter is an array of some sort. If i simply place a string
such as "param1=value1&param2=value2" (which I think is what your code
is doing) it simply does a GET request and the data is discarded.

I think the issue is that the "navigate" method is expecting a byte
array but from what I can see, all the values in ruby are 32 bits
which is 4 bytes therefore I'm sending extra data.

I still don't know how to change the output from "each_byte" into 8
bits instead of a 32 bit integer to make this call work.

-Bach
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top