# Switch User Agent

**URL:** <https://rubytalk.org/t/switch-user-agent/23076>\
**Category:** ruby-talk\
**Created:** [7 December 2005 13:59 UTC](https://rubytalk.org/t/switch-user-agent/23076 "2005-12-07T13:59:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Amat](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Alex\_Amat](https://rubytalk.org/u/Alex_Amat)\
**Post date:** [7 December 2005 13:59 UTC](https://rubytalk.org/t/switch-user-agent/23076/1 "2005-12-07T13:59:14Z")

</div>

Hi all I'm writing an application in ruby and I need to change the  
UAProof of an HTTP request that I'm sending out. (To pretend that my  
browser is a mobile phone) does anyone know how to go about it.

Many thanks

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Gene\_Tani](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@Gene\_Tani](https://rubytalk.org/u/Gene_Tani)\
**Post date:** [7 December 2005 14:22 UTC](https://rubytalk.org/t/switch-user-agent/23076/2 "2005-12-07T14:22:35Z")

</div>

Alex Amat wrote:

> Hi all I'm writing an application in ruby and I need to change the  
> UAProof of an HTTP request that I'm sending out. (To pretend that my  
> browser is a mobile phone) does anyone know how to go about it.
> 
> Many thanks
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

I haven't seent the term UAproof before, but the open-uri and Net::HTTP  
ways of opening URLs are both dict-like as far as passing User-Agents  
etc:

[http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/](http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/)

e.g.  
Net::HTTP.start( 'www.digg.com', 80 ) do |http|  
print( http.get( '/', "User-Agent" =\> "foobar" ).body ) ; end

setting referrer/referer (can't remember which is correct!) is similar

---

<div class="post-metadata">

**Author:** ![Gene\_Tani](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@Gene\_Tani](https://rubytalk.org/u/Gene_Tani)\
**Post date:** [7 December 2005 14:22 UTC](https://rubytalk.org/t/switch-user-agent/23076/3 "2005-12-07T14:22:41Z")

</div>

Gene Tani wrote:

> Alex Amat wrote:  
> \> Hi all I'm writing an application in ruby and I need to change the  
> \> UAProof of an HTTP request that I'm sending out. (To pretend that my  
> \> browser is a mobile phone) does anyone know how to go about it.  
> \>  
> \> Many thanks  
> \>  
> \> --  
> \> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> I haven't seent the term UAproof before, but the open-uri and Net::HTTP  
> ways of opening URLs are both dict-like as far as passing User-Agents  
> etc:
> 
> [http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/](http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/)
> 
> e.g.  
> Net::HTTP.start( 'www.digg.com', 80 ) do |http|  
> print( http.get( '/', "User-Agent" =\> "foobar" ).body ) ; end
> 
> setting referrer/referer (can't remember which is correct!) is similar

whoops, forgot the great zenspider slides:

> **[open-uri.pdf](https://www.zenspider.com/dl/rubyconf2005/open-uri.pdf)**
>
> 189.74 KB

---

<div class="post-metadata">

**Author:** ![Alex\_Amat](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Alex\_Amat](https://rubytalk.org/u/Alex_Amat)\
**Post date:** [7 December 2005 15:00 UTC](https://rubytalk.org/t/switch-user-agent/23076/4 "2005-12-07T15:00:10Z")

</div>

Sorry mate I meant User Agent (I'm a bit new to the world of ruby and  
internet)  
What I'm doing is a web site that changes normal PC websites into MCS  
sites I've got three ifreams so that the rendered sites can be  
previewed, all I need to do is change the user agent of the request  
object so that my application delivers the content for different user  
agents.

Thanks a lot !

gene.tani wrote:

> **···**
>
> > Gene Tani wrote:
> > 
> > > I haven't seent the term UAproof before, but the open-uri and Net::HTTP  
> > > ways of opening URLs are both dict-like as far as passing User-Agents  
> > > etc:
> > > 
> > > [http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/](http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/)
> > > 
> > > e.g.  
> > > Net::HTTP.start( 'www.digg.com', 80 ) do |http|  
> > > print( http.get( '/', "User-Agent" =\> "foobar" ).body ) ; end
> > > 
> > > setting referrer/referer (can't remember which is correct!) is similar
> > 
> > whoops, forgot the great zenspider slides:  
> > [http://www.zenspider.com/dl/rubyconf2005/open-uri.pdf](http://www.zenspider.com/dl/rubyconf2005/open-uri.pdf)
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
