From: Bach Le Date: 2007-11-16T07:40:00+09:00 Subject: Re: Adding Post Data to IE.navigate method with Ruby On Nov 15, 2:12 pm, Paul Rogers wrote: > On Nov 15, 11:40 am, Bach Le wrote: > > > > > 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 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¶m2=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