Welcome to Dream.In.Code
Getting Help is Easy!

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




http.post

2 Pages V  1 2 >  
Reply to this topicStart new topic

http.post, posting to a web page

rrkrr
post 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

Go to the top of the page

rrkrr
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

Go to the top of the page

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


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 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

Go to the top of the page

rrkrr
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

Go to the top of the page

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


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 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

Go to the top of the page

rrkrr
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

Go to the top of the page

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


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 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

Go to the top of the page

rrkrr
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

Go to the top of the page

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


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 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

Go to the top of the page

rrkrr
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

Go to the top of the page

rrkrr
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

Go to the top of the page

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


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 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

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 04:41PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month