http.post

posting to a web page

Page 1 of 1

13 Replies - 4761 Views - Last Post: 14 October 2008 - 10:44 PM Rate Topic: -----

#1 rrkrr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-October 08

http.post

Posted 09 October 2008 - 08:04 PM

I am hoping someone could explain
resp, data = http.post(path, data, header)
in simple terms.
Is This A Good Question/Topic? 0
  • +

Replies To: http.post

#2 rrkrr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-October 08

Re: http.post

Posted 10 October 2008 - 08:51 PM

I would also appreciate any information on
resp, data = http.get(path, header)
thanx
Was This Post Helpful? 0
  • +
  • -

#3 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: http.post

Posted 10 October 2008 - 10:30 PM

In the official focumentation is very well explained almost every method.
For example in the online API ( or using 'ri Net::HTTP#post' ) :

Quote

post(path, data, initheader = nil, dest = nil) {|+body_segment+| ...}
Posts data (must be a String) to path. header must be a Hash like { ‘Accept’ => ’*/*’, … }.

In version 1.1 (ruby 1.6), this method returns a pair of objects, a Net::HTTPResponse object and an entity body string. In version 1.2 (ruby 1.8), this method returns a Net::HTTPResponse object.

If called with a block, yields each fragment of the entity body in turn as a string as it are read from the socket. Note that in this case, the returned response object will not contain a (meaningful) body.

dest argument is obsolete. It still works but you must not use it.

In version 1.1, this method might raise an exception for 3xx (redirect). In this case you can get an HTTPResponse object by "anException.response". In version 1.2, this method never raises exception.

This post has been edited by MitkOK: 10 October 2008 - 10:32 PM

Was This Post Helpful? 0
  • +
  • -

#4 rrkrr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-October 08

Re: http.post

Posted 11 October 2008 - 07:32 PM

thank you MitkOK
although I don't understand completely, it was still a help.
what I am attempting to accomplish is being able to put data on a table on a web page.
is resp,
data = http.post(path, data, header)
the way to go, or is there another way.
Was This Post Helpful? 0
  • +
  • -

#5 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: http.post

Posted 12 October 2008 - 03:32 AM

You want to put data into html table ( <table> ... </table> ) ?
Because http.post is for porccessing POST query.
Was This Post Helpful? 0
  • +
  • -

#6 rrkrr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-October 08

Re: http.post

Posted 12 October 2008 - 10:19 PM

<form method="POST"
yep it is a post.
Was This Post Helpful? 0
  • +
  • -

#7 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: http.post

Posted 13 October 2008 - 01:50 AM

Ok, now explain what exactly you wnat to do, because "what I am attempting to accomplish is being able to put data on a table on a web page." has nothing to do with POST ...
Was This Post Helpful? 0
  • +
  • -

#8 rrkrr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-October 08

Re: http.post

Posted 13 October 2008 - 07:20 PM

i am making a program that will read a text file (this part is done), then input that data on to a form (looks like a table) on the internet.

currently you have to enter your numbers manually on to the form, choose a radio button, and then press the OK button. next the web page takes this data and shows it to you to confirm. then you press OK again.

that is basically what i am trying to automate.

my problem is that I really do not know how to enter data on to a webpage. I can make a program to read the data, I just don't know how to write the data.
Was This Post Helpful? 0
  • +
  • -

#9 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: http.post

Posted 14 October 2008 - 12:46 AM

If you want to post data to a form you might look at Mechanize :

Example using Mechanize to query Google :
Google
  require 'rubygems'
  require 'mechanize'

  a = WWW::Mechanize.new { |agent|
    agent.user_agent_alias = 'Mac Safari'
  }

  a.get('http://google.com/') do |page|
    search_result = page.form_with(:name => 'f') do |search|
      search.q = 'Hello world'
    end.submit

    search_result.links.each do |link|
      puts link.text
    end
  end

Was This Post Helpful? 0
  • +
  • -

#10 rrkrr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-October 08

Re: http.post

Posted 14 October 2008 - 04:48 AM

thank you, I think this is what I am looking for. :-)

I just downloaded mechanize 0.8.4
now comes my next question, where do I put this library?

This post has been edited by rrkrr: 14 October 2008 - 06:08 AM

Was This Post Helpful? 0
  • +
  • -

#11 rrkrr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-October 08

Re: http.post

Posted 14 October 2008 - 06:19 AM

I figured it out where to put it.
Was This Post Helpful? 0
  • +
  • -

#12 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: http.post

Posted 14 October 2008 - 09:32 AM

In Ruby most of the external libs are installed as gem and included with 'require'.
Was This Post Helpful? 0
  • +
  • -

#13 rrkrr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-October 08

Re: http.post

Posted 14 October 2008 - 06:19 PM

"The best way to predict the future is to implement it."

I like that moto, where did you get it.
Was This Post Helpful? 0
  • +
  • -

#14 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: http.post

Posted 14 October 2008 - 10:44 PM

It's David Heinemeier Hansson quote ( the creator of Ruby on Rails web framework ) which is slightly changed quote of Alan Kay ( the creator of Smalltalk ).

This post has been edited by MitkOK: 14 October 2008 - 10:46 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1