any good library to send POST headers in ruby ?
+2
A:
The standard library Net::HTTP is pretty straightforward and handles POST
.
From the docs:
response = http.post('/cgi-bin/search.rb', 'query=foo')
# using block
File.open('result.txt', 'w') {|f|
http.post('/cgi-bin/search.rb', 'query=foo') do |str|
f.write str
end
}
For more detailed examples of how to use Net::HTTP, see August Lilleaas's Net::HTTP cheat sheet repository on Github.
Telemachus
2010-08-22 20:10:29
You don't say what the `http` object is, or how to get it
Pablo Fernandez
2010-08-22 20:28:50
@Pablo That's correct; I don't. As I said, I grabbed that example directly from Net::HTTP's documentation (which I linked to). I assumed that the OP would follow up by learning how to use Net::HTTP. (Teach a person to fish...)
Telemachus
2010-08-22 20:45:04
Nice job linking the cheatsheet though... I had edited that but rolled it back 'cause it seemed like too intrusive. Best answer overall = +10
Pablo Fernandez
2010-08-23 07:14:47
A:
You can do something like this...
require 'net/http'
require 'uri'
postData = Net::HTTP.post_form(URI.parse('http://thewebsite.net'), {'postKey'=>'postValue'})
puts postData.body
krio
2010-08-22 21:57:07
A:
There are plenty of HTTP libraries in Ruby. There's the standard net/http and libcurl bindings. But there are also a lot of high-level libraries to consume web services such as ActiveResource and HTTParty. Depends on what you want to do. Maybe you can update your question with more information?
AboutRuby
2010-08-22 22:53:16