example of Net:HTTP::Put ?

C

Chris McMahon

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?
 
E

eden li

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
 
C

Chris McMahon

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,259
Messages
2,571,295
Members
47,931
Latest member
alibsskamoSeAve

Latest Threads

Top