# Http.post 1.8.4 bug?

**URL:** <https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852>\
**Category:** Ruby\
**Created:** [August 21, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852 "2006-08-21T22:04:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [August 21, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852/1 "2006-08-21T22:04:28Z")

</div>

I’m having a problem with http.post for ruby 1.8.4. Specifically, the  
server I’m posting to is complaining that it is not getting all the  
parameter I’m sending.

This code snippet works in version 1.8.2 but fails in 1.8.4

@http = Net::HTTP.new( server, port )  
@headers[‘Content-Type’] = ‘text/html’  
data = ‘Type=METADATA-SYSTEM&ID=0’  
resp = @http.post(uri,data,@headers )

The server I’m posting appears to only get the first parameter  
‘Type=METADATA’ but is complaining that the second paramert ‘ID=0’ is  
missing. Switching order doesn’t matter.

There was a similar issue reported on rubyforge.  
[http://rubyforge.org/tracker/?func=detail&atid=1698&aid=4782&group\_id=426](http://rubyforge.org/tracker/?func=detail&atid=1698&aid=4782&group_id=426)  
I updated the feedvalidator and am also manually setting the  
content-type but nothing seems to work.

I’m talking to an [ASP.NET](http://ASP.NET), if that matters.

Making things more confusing, this bit of code seems to work.

require ‘net/http’

Net::HTTP.start(‘[www.snee.com](http://www.snee.com)’, 80) {|http|  
result = http.post(‘/xml/crud/posttest.cgi’,  
‘fname=works&lname=here’)  
puts result  
}

Any help would be greatly appreciated!

Regards,  
Mike

---

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [August 21, 2006, 10:12pm UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852/2 "2006-08-21T22:12:25Z")

</div>

You forgot to set the content-length header.

---

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [August 21, 2006, 10:45pm UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852/3 "2006-08-21T22:45:46Z")

</div>

snacktime wrote:

> You forgot to set the content-length header.

Thanks, I tried it but I’m still getting the error. The code works fine  
in 1.8.2 and I don’t have to set content-length. I think it might be  
something else.

Would there be a reason I’d need to set this in 1.8.4 and not in 1.8.2  
to get http.post to work correctly?

Mike

---

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [August 21, 2006, 11:30pm UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852/4 "2006-08-21T23:30:26Z")

</div>

snacktime wrote:

> On 8/21/06, Mike L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > snacktime wrote:
> > 
> > > You forgot to set the content-length header.
> > 
> > Thanks, I tried it but I’m still getting the error. The code works fine  
> > in 1.8.2 and I don’t have to set content-length. I think it might be  
> > something else.
> > 
> > Would there be a reason I’d need to set this in 1.8.4 and not in 1.8.2  
> > to get http.post to work correctly?
> 
> Aren’t dashes supposed to be escaped? You might try escaping the post  
> data and see if that does it.

Tried it just for grins and still get the same issue. Odd thing, It  
doens’t appear to be related to order or number of parameters.

---

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [August 22, 2006, 1:45am UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852/5 "2006-08-22T01:45:42Z")

</div>

Mike L. wrote:

> snacktime wrote:
> 
> > On 8/21/06, Mike L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > snacktime wrote:
> > > 
> > > > You forgot to set the content-length header.
> > > 
> > > Thanks, I tried it but I’m still getting the error. The code works fine  
> > > in 1.8.2 and I don’t have to set content-length. I think it might be  
> > > something else.
> > > 
> > > Would there be a reason I’d need to set this in 1.8.4 and not in 1.8.2  
> > > to get http.post to work correctly?
> > 
> > Aren’t dashes supposed to be escaped? You might try escaping the post  
> > data and see if that does it.
> 
> Tried it just for grins and still get the same issue. Odd thing, It  
> doens’t appear to be related to order or number of parameters.

Just an FYI for anyone else who comes uppon this, I figured out what my  
problem was.

This line:  
@headers[‘Content-Type’] = ‘text/html’

Should have been:  
@headers[‘content-type’] = ‘application/x-www-form-urlencoded’

I didn’t have the content-type set correctly. With 1.8.4 you have to  
explicitly set it. ( This was the but and it has been fixed, from what  
I gather. ) I just was not setting it to the correct value.

Cheers,  
Mike

---

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [August 22, 2006, 2:12am UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852/6 "2006-08-22T02:12:49Z")

</div>

Mike L. wrote:

> I’m talking to an [ASP.NET](http://ASP.NET), if that matters.  
> puts result  
> }
> 
> Any help would be greatly appreciated!
> 
> Regards,  
> Mike

Hi Mike,  
I have similiar problem trying to proxy PHP application. Did you found  
any solution?

best regards,  
Bojan M.

---

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [August 21, 2006, 11:04pm UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852/7 "2006-08-21T23:04:30Z")

</div>

On 8/21/06, Mike L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> snacktime wrote:
> 
> > You forgot to set the content-length header.
> 
> Thanks, I tried it but I’m still getting the error. The code works fine  
> in 1.8.2 and I don’t have to set content-length. I think it might be  
> something else.
> 
> Would there be a reason I’d need to set this in 1.8.4 and not in 1.8.2  
> to get http.post to work correctly?

Aren’t dashes supposed to be escaped? You might try escaping the post  
data and see if that does it.

---

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [August 22, 2006, 8:23am UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852/8 "2006-08-22T08:23:19Z")

</div>

Mike L. wrote:

> > > Mike  
> > > you have to manually set it. See the link to the bug earlier in the  
> > > thread.
> 
> Hope this helps with your problem.
> 
> Mike

Thanks Mike,  
this saves my day 🙂

---

<div class="post-metadata">

**Author:** ![mlopke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mlopke](https://www.ruby-forum.com/u/mlopke)\
**Post date:** [August 22, 2006, 2:23am UTC](https://www.ruby-forum.com/t/http-post-1-8-4-bug/65852/9 "2006-08-22T02:23:18Z")

</div>

Bojan M. wrote:

> Mike L. wrote:
> 
> > I’m talking to an [ASP.NET](http://ASP.NET), if that matters.  
> > puts result  
> > }
> > 
> > Any help would be greatly appreciated!
> > 
> > Regards,  
> > Mike
> 
> Hi Mike,  
> I have similiar problem trying to proxy PHP application. Did you found  
> any solution?
> 
> best regards,  
> Bojan M.

Looks like I snuck in the answer before your question. 🙂 Setting the  
content-type to the correct value fixed things for me. For ruby 1.8.4  
you have to manually set it. See the link to the bug earlier in the  
thread.

Hope this helps with your problem.

Mike
