# HTTP Headers

**URL:** <https://www.ruby-forum.com/t/http-headers/237990>\
**Category:** Ruby\
**Created:** [December 10, 2013, 4:54pm UTC](https://www.ruby-forum.com/t/http-headers/237990 "2013-12-10T16:54:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [December 10, 2013, 4:54pm UTC](https://www.ruby-forum.com/t/http-headers/237990/1 "2013-12-10T16:54:16Z")

</div>

Hey guys, I need to make a HTTP GET in a page, but I need to use the  
header X-Requested-With : XMLHttpRequest, but I have no idea how to do  
this.  
by the way I’m new in ruby.

---

<div class="post-metadata">

**Author:** ![eduardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6a8cbe/32.png) [@eduardo](https://www.ruby-forum.com/u/eduardo)\
**Post date:** [December 10, 2013, 4:58pm UTC](https://www.ruby-forum.com/t/http-headers/237990/2 "2013-12-10T16:58:28Z")

</div>

On Tue, Dec 10, 2013 at 4:54 PM, Eduardo N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hey guys, I need to make a HTTP GET in a page, but I need to use the  
> header X-Requested-With : XMLHttpRequest, but I have no idea how to do  
> this.  
> by the way I’m new in ruby.

I think we need more info to help you. You need to make a GET _in_ a  
page but you need to do it in Ruby? I’m not sure you really mean that.  
Is it that you need to issue a GET request from within a web page  
(then look at AJAX, javascript), or is it that you wan to use Ruby to  
perform that request within a script, for example?

If it’s the last one, we might be able to help you if you tell us more  
about it.

Jesus.

---

<div class="post-metadata">

**Author:** ![eduardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6a8cbe/32.png) [@eduardo](https://www.ruby-forum.com/u/eduardo)\
**Post date:** [December 10, 2013, 5:01pm UTC](https://www.ruby-forum.com/t/http-headers/237990/3 "2013-12-10T17:01:47Z")

</div>

“Jesús Gabriel y Galán” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in post  
#1130261:

> On Tue, Dec 10, 2013 at 4:54 PM, Eduardo N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hey guys, I need to make a HTTP GET in a page, but I need to use the  
> > header X-Requested-With : XMLHttpRequest, but I have no idea how to do  
> > this.  
> > by the way I’m new in ruby.
> 
> I think we need more info to help you. You need to make a GET _in_ a  
> page but you need to do it in Ruby? I’m not sure you really mean that.  
> Is it that you need to issue a GET request from within a web page  
> (then look at AJAX, javascript), or is it that you wan to use Ruby to  
> perform that request within a script, for example?
> 
> If it’s the last one, we might be able to help you if you tell us more  
> about it.
> 
> Jesus.

Yes, I want to use ruby to perform a request with that header, sorry for  
my bad english.

---

<div class="post-metadata">

**Author:** ![eduardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6a8cbe/32.png) [@eduardo](https://www.ruby-forum.com/u/eduardo)\
**Post date:** [December 11, 2013, 11:50am UTC](https://www.ruby-forum.com/t/http-headers/237990/4 "2013-12-11T11:50:42Z")

</div>

2013/12/10 Jess Gabriel y Galn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> re also a number of gems to help with HTTP requests: mechanize,  
> httparty, etc, depending on what you want to

If I understood your problem correctly, maybe this gem could also be an  
option:

> **[GitHub - jnunemaker/httparty: :tada: Makes http fun again!](https://github.com/jnunemaker/httparty)**
>
> :tada: Makes http fun again!

–  
Thyago Barbosa Rodrigues [Natal-RN/Brasil]

“Who loves not wine, women and song,  
remains a fool his whole life long”  
(Martin Luther [Martinho Lutero], Telogo Alemo)

“Phantasie ist wichtiger als Wissen, denn Wissen ist begrenzt.” (Albert  
Einstein)

---

<div class="post-metadata">

**Author:** ![eduardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6a8cbe/32.png) [@eduardo](https://www.ruby-forum.com/u/eduardo)\
**Post date:** [December 10, 2013, 5:10pm UTC](https://www.ruby-forum.com/t/http-headers/237990/5 "2013-12-10T17:10:45Z")

</div>

On Tue, Dec 10, 2013 at 5:01 PM, Eduardo N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > page but you need to do it in Ruby? I’m not sure you really mean that.  
> > my bad english.
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

You can use the stdlib class Net::HTTP, see here an example of setting  
a header:  
[http://www.ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTP.html#class-Net::HTTP-label-Setting+Headers](http://www.ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTP.html#class-Net::HTTP-label-Setting+Headers)

There also a number of gems to help with HTTP requests: mechanize,  
httparty, etc, depending on what you want to do.

Jesus.
