School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,406 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,599 people online right now. Registration is fast and FREE... Join Now!




http.post

 

http.post, posting to a web page

rrkrr

9 Oct, 2008 - 07:04 PM
Post #1

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 8

I am hoping someone could explain
resp, data = http.post(path, data, header)
in simple terms.

User is offlineProfile CardPM
+Quote Post


rrkrr

RE: Http.post

10 Oct, 2008 - 07:51 PM
Post #2

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 8

I would also appreciate any information on
resp, data = http.get(path, header)
thanx
User is offlineProfile CardPM
+Quote Post

MitkOK

RE: Http.post

10 Oct, 2008 - 09:30 PM
Post #3

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 356



Thanked: 19 times
Dream Kudos: 250
My Contributions
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 Oct, 2008 - 09:32 PM
User is offlineProfile CardPM
+Quote Post

rrkrr

RE: Http.post

11 Oct, 2008 - 06:32 PM
Post #4

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 8

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,
CODE
data = http.post(path, data, header)
the way to go, or is there another way.
User is offlineProfile CardPM
+Quote Post

MitkOK

RE: Http.post

12 Oct, 2008 - 02:32 AM
Post #5

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 356



Thanked: 19 times
Dream Kudos: 250
My Contributions
You want to put data into html table ( <table> ... </table> ) ?
Because http.post is for porccessing POST query.
User is offlineProfile CardPM
+Quote Post

rrkrr

RE: Http.post

12 Oct, 2008 - 09:19 PM
Post #6

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 8

<form method="POST"
yep it is a post.

User is offlineProfile CardPM
+Quote Post

MitkOK

RE: Http.post

13 Oct, 2008 - 12:50 AM
Post #7

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 356



Thanked: 19 times
Dream Kudos: 250
My Contributions
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 ...
User is offlineProfile CardPM
+Quote Post

rrkrr

RE: Http.post

13 Oct, 2008 - 06:20 PM
Post #8

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 8

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.

User is offlineProfile CardPM
+Quote Post

MitkOK

RE: Http.post

13 Oct, 2008 - 11:46 PM
Post #9

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 356



Thanked: 19 times
Dream Kudos: 250
My Contributions
If you want to post data to a form you might look at Mechanize :

Example using Mechanize to query Google :
ruby
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

User is offlineProfile CardPM
+Quote Post

rrkrr

RE: Http.post

14 Oct, 2008 - 03:48 AM
Post #10

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 8

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 Oct, 2008 - 05:08 AM
User is offlineProfile CardPM
+Quote Post

rrkrr

RE: Http.post

14 Oct, 2008 - 05:19 AM
Post #11

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 8

I figured it out where to put it.
User is offlineProfile CardPM
+Quote Post

MitkOK

RE: Http.post

14 Oct, 2008 - 08:32 AM
Post #12

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 356



Thanked: 19 times
Dream Kudos: 250
My Contributions
In Ruby most of the external libs are installed as gem and included with 'require'.
User is offlineProfile CardPM
+Quote Post

rrkrr

RE: Http.post

14 Oct, 2008 - 05:19 PM
Post #13

New D.I.C Head
*

Joined: 9 Oct, 2008
Posts: 8

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

I like that moto, where did you get it.
User is offlineProfile CardPM
+Quote Post

MitkOK

RE: Http.post

14 Oct, 2008 - 09:44 PM
Post #14

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 356



Thanked: 19 times
Dream Kudos: 250
My Contributions
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 Oct, 2008 - 09:46 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:43PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month