# Generating http post in Ruby

**URL:** <https://www.ruby-forum.com/t/generating-http-post-in-ruby/88546>\
**Category:** Rails\
**Created:** [March 12, 2007, 3:39pm UTC](https://www.ruby-forum.com/t/generating-http-post-in-ruby/88546 "2007-03-12T15:39:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 12, 2007, 3:39pm UTC](https://www.ruby-forum.com/t/generating-http-post-in-ruby/88546/1 "2007-03-12T15:39:48Z")

</div>

Hi, I’m in need to send a file throught an http post and examine the  
response within a Rails project.  
Net::HTTP is powerful but way too hard to use, I’m in need of  
something slick and quick to use and manage.

Actually I’ve found Curb, which works like a charm (  
[http://rubyforge.org/projects/curb](http://rubyforge.org/projects/curb) ) but it has a big problem: it  
depends on external libraries (curlib) and doesn’t work at all on win  
(which is the platform used by most of our team).

What would really be a great tool is an high level libraries which  
relies on Net::HTTP o similar, which allows me to achieve my results  
with really compact statements.

Curb is really smart at this:

```
c = Curl::Easy.new post_url
c.multipart_form_post = true
c.http_post(
  Curl::PostField.content('some_var_name', some_var_value),
  Curl::PostField.file('file_name', incomming_file.path)
)
puts c.body_str if c.response_code == 200

```

## Is there any other similar library that can work on multiple platforms

Ashkey \< Jules Piccotti

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 12, 2007, 3:46pm UTC](https://www.ruby-forum.com/t/generating-http-post-in-ruby/88546/2 "2007-03-12T15:46:49Z")

</div>

On Mon, 12 Mar 2007, Ashkey wrote:

> What would really be a great tool is an high level libraries which  
> )  
> puts c.body\_str if c.response\_code == 200
> 
> Is there any other similar library that can work on multiple platforms

check out http-access2 and mechanize

-a

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 12, 2007, 3:41pm UTC](https://www.ruby-forum.com/t/generating-http-post-in-ruby/88546/3 "2007-03-12T15:41:49Z")

</div>

Hi, I’m in need to send a file throught an http post and examine the  
response within a Rails project.  
Net::HTTP is powerful but way too hard to use, I’m in need of  
something slick and quick to use and manage.

Actually I’ve found Curb, which works like a charm (  
[http://rubyforge.org/projects/curb](http://rubyforge.org/projects/curb) ) but it has a big problem: it  
depends on external libraries (curlib) and doesn’t work at all on win  
(which is the platform used by most of our team).

What would really be a great tool is an high level libraries which  
relies on Net::HTTP o similar, which allows me to achieve my results  
with really compact statements.

Curb is really smart at this:

```
c = Curl::Easy.new post_url
c.multipart_form_post = true
c.http_post(
  Curl::PostField.content('some_var_name', some_var_value),
  Curl::PostField.file('file_name', incomming_file.path)
)
puts c.body_str if c.response_code == 200

```

Is there any other similar library that can work on multiple platforms

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 12, 2007, 3:59pm UTC](https://www.ruby-forum.com/t/generating-http-post-in-ruby/88546/4 "2007-03-12T15:59:51Z")

</div>

Hi Jules,

Ashkey wrote:

> Hi, I’m in need to send a file throught an http post  
> and examine the response within a Rails project.  
> Net::HTTP is powerful but way too hard to use,  
> I’m in need of something slick and quick to use and  
> manage.

I’m not sure I understand you completely. What is it that the send\_file  
or  
send\_data methods ([api.rubyonrails.org](http://api.rubyonrails.org)) don’t do that you need?

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 12, 2007, 5:16pm UTC](https://www.ruby-forum.com/t/generating-http-post-in-ruby/88546/5 "2007-03-12T17:16:05Z")

</div>

On Mar 12, 2007, at 10:38 AM, Ashkey wrote:

> What would really be a great tool is an high level libraries which  
> )  
> puts c.body\_str if c.response\_code == 200

That doesn’t look much easier than Net::HTTP.

my\_form\_data = {:title =\> ‘Example’, :body =\> ‘Content’}

res = Net::HTTP.post\_form(  
URI.parse(‘[http://www.example.com/recipient/](http://www.example.com/recipient/)’),  
my\_form\_data)

```
    puts res.response.body if res.response.code == 200

```

What is it about Curl that you prefer?

James.
