I am hoping someone could explain
resp, data = http.post(path, data, header)
in simple terms.
http.postposting to a web page
Page 1 of 1
13 Replies - 4558 Views - Last Post: 14 October 2008 - 10:44 PM
Replies To: http.post
#2
Re: http.post
Posted 10 October 2008 - 08:51 PM
I would also appreciate any information on
resp, data = http.get(path, header)
thanx
resp, data = http.get(path, header)
thanx
#3
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' ) :
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.
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
#4
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,
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.
#5
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.
Because http.post is for porccessing POST query.
#6
Re: http.post
Posted 12 October 2008 - 10:19 PM
<form method="POST"
yep it is a post.
yep it is a post.
#7
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 ...
#8
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.
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.
#9
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 :
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
#10
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?
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
#12
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'.
#13
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.
I like that moto, where did you get it.
#14
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
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|