[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

example of Net:HTTP::Put ?

Chris McMahon

5/12/2007 12:50:00 AM


I've been trying to use Net::HTTP:Put. My server isn't returning any
errors, but I'm not accomplishing anything either. Googling turns up
very little.

Are there any examples of an HTTP PUT command using Ruby on the web?

3 Answers

eden li

5/12/2007 5:31:00 AM

0

Here's a quick and dirty one. You can find more about Net::HTTP via
its rdocs. If you've installed ri on your system, run `ri
Net::HTTP#send_request` and `ri Net::HTTP`

#!/usr/bin/env ruby
require 'net/http'

unless uri = (URI.parse(ARGV.shift) rescue nil)
puts "Usage: #$0 <url>"
exit
end

puts "Sending PUT #{uri.request_uri} to #{uri.host}:#{uri.port}"
Net::HTTP.start(uri.host, uri.port) do |http|
headers = {'Content-Type' => 'text/plain; charset=utf-8'}
put_data = "put payload"
response = http.send_request('PUT', uri.request_uri, put_data,
headers)
puts "Response #{response.code} #{response.message}:
#{response.body}"
end

On May 12, 8:50 am, Chris McMahon <christopher.mcma...@gmail.com>
wrote:
> I've been trying to use Net::HTTP:Put. My server isn't returning any
> errors, but I'm not accomplishing anything either. Googling turns up
> very little.
>
> Are there any examples of an HTTP PUT command using Ruby on the web?


Chris McMahon

5/21/2007 9:12:00 PM

0


Sorry for the late reply...
Any chance of also negotiating a 302 redirect?

<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://foo.bar.com/doc">here</a...
p>


On May 11, 11:31 pm, eden li <eden...@gmail.com> wrote:
> Here's a quick and dirty one. You can find more about Net::HTTPvia
> its rdocs. If you've installed ri on your system, run `ri
> Net::HTTP#send_request` and `ri Net::HTTP`
>
> #!/usr/bin/env ruby
> require 'net/http'
>
> unless uri = (URI.parse(ARGV.shift) rescue nil)
> puts "Usage: #$0 <url>"
> exit
> end
>
> puts "SendingPUT#{uri.request_uri} to #{uri.host}:#{uri.port}"
> Net::HTTP.start(uri.host, uri.port) do |http|
> headers = {'Content-Type' => 'text/plain; charset=utf-8'}
> put_data = "putpayload"
> response =http.send_request('PUT', uri.request_uri, put_data,
> headers)
> puts "Response #{response.code} #{response.message}:
> #{response.body}"
> end
>
> On May 12, 8:50 am, ChrisMcMahon<christopher.mcma...@gmail.com>
> wrote:
>
> > I've been trying to use Net::HTTP:Put. My server isn't returning any
> > errors, but I'm not accomplishing anything either. Googling turns up
> > very little.
>
> > Are there any examples of anHTTPPUTcommand using Ruby on the web?


Carl

5/21/2007 9:25:00 PM

0

Chris McMahon <christopher.mcmahon@gmail.com> writes:

> Sorry for the late reply...
> Any chance of also negotiating a 302 redirect?
>
> <title>302 Found</title>
> </head><body>
> <h1>Found</h1>
> <p>The document has moved <a href="http://foo.bar.com/doc">here</a...
> p>
>
>

There is a section on following redirection on the ruby-doc site. See:
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net...

Hope that helps,
Carl.