# Simple example of failed attempts to use a user agent header

**URL:** <https://www.ruby-forum.com/t/simple-example-of-failed-attempts-to-use-a-user-agent-header/94121>\
**Category:** Ruby\
**Created:** [April 21, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/simple-example-of-failed-attempts-to-use-a-user-agent-header/94121 "2006-04-21T20:15:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xeno\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/958977/32.png) [@Xeno\_C](https://www.ruby-forum.com/u/Xeno_C)\
**Post date:** [April 21, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/simple-example-of-failed-attempts-to-use-a-user-agent-header/94121/1 "2006-04-21T20:15:38Z")

</div>

When I try to use the User-Agent header in a hash, I get:

$ ./tryua01.rb  
/usr/lib/ruby/1.8/net/protocol.rb:83:in `initialize': can't convert URI::HTTP into String (TypeError) from /usr/lib/ruby/1.8/net/protocol.rb:83:in `connect’  
from /usr/lib/ruby/1.8/net/protocol.rb:82:in `timeout' from /usr/lib/ruby/1.8/timeout.rb:62:in `timeout’  
from /usr/lib/ruby/1.8/net/protocol.rb:82:in `connect' from /usr/lib/ruby/1.8/net/protocol.rb:64:in `initialize’  
from /usr/lib/ruby/1.8/net/http.rb:429:in `do_start' from /usr/lib/ruby/1.8/net/http.rb:418:in `start’  
from /usr/lib/ruby/1.8/net/http.rb:286:in `get_by_path' from /usr/lib/ruby/1.8/net/http.rb:279:in `get\_response’  
from ./tryua01.rb:10

where my simplified code is as follows:

#!/usr/bin/ruby

require ‘net/http’  
require ‘uri’

uah = \<\<EOUAH  
Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.7.10) Gecko/20050716  
Firefox/1.0.6  
EOUAH  
uri\_str = “[http://www.eskimo.com](http://www.eskimo.com)” response =  
Net::HTTP.get\_response(URI.parse(uri\_str),{‘User-Agent’ =\> uah})  
#response = Net::HTTP.get\_response(URI.parse(uri\_str))  
p response.body[500,55]

when I comment out the first get\_response line and use the second one  
without  
the UA header the script works just fine.

xc
