# Adding Post Data to IE.navigate method with Ruby

**URL:** <https://www.ruby-forum.com/t/adding-post-data-to-ie-navigate-method-with-ruby/120321>\
**Category:** Ruby\
**Created:** [November 15, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/adding-post-data-to-ie-navigate-method-with-ruby/120321 "2007-11-15T19:45:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bach\_Le](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@Bach\_Le](https://www.ruby-forum.com/u/Bach_Le)\
**Post date:** [November 15, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/adding-post-data-to-ie-navigate-method-with-ruby/120321/1 "2007-11-15T19:45:51Z")

</div>

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 ([Navigate method (Internet Explorer) | Microsoft Learn](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

---

<div class="post-metadata">

**Author:** ![Bach\_Le](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@Bach\_Le](https://www.ruby-forum.com/u/Bach_Le)\
**Post date:** [November 15, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/adding-post-data-to-ie-navigate-method-with-ruby/120321/2 "2007-11-15T23:15:26Z")

</div>

On Nov 15, 11:40 am, Bach Le [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 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](http://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

---

<div class="post-metadata">

**Author:** ![Bach\_Le](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/439d5e/32.png) [@Bach\_Le](https://www.ruby-forum.com/u/Bach_Le)\
**Post date:** [November 15, 2007, 11:40pm UTC](https://www.ruby-forum.com/t/adding-post-data-to-ie-navigate-method-with-ruby/120321/3 "2007-11-15T23:40:39Z")

</div>

On Nov 15, 2:12 pm, Paul R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Seems like the postdata parameter is a byte array so here’s what I’ve
> 
> 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
