From: Clifford Heath Date: 2009-09-13T13:15:06+09:00 Subject: Re: Asynchronous http POST? Ivan Shevanski wrote: > I couldn't seem to get this running with threads, so I'm trying > eventmachine. I think EM is overkill here. The following example uses PUT not POST, but I'm sure you'll be able to adapt it. require 'net/http' require 'uri' # Configuration variables: THREAD_COUNT = 10 REQUESTS_PER_THREAD = 10 FILENAME = 'file_to_put' URL = 'http://localhost/DropBox/file_to_put' # Put a data string to the specified url: def urlput(url, data) begin uri = URI.parse(url) response = nil value = nil Net::HTTP.start(uri.host) { |http| response, value = http.put(uri.path, data, nil) } p response.message if (response.code.to_i >= 300) rescue => e p e end value end # Read the file to put: data = File.new(FILENAME).read start = Time.now $threads = [] (1..THREAD_COUNT).each {|thread| $threads << Thread.new(thread) { |thread_no| (1..REQUESTS_PER_THREAD).each { urlput(URL, data) } } } $threads.each { |aThread| aThread.join } puts "#{THREAD_COUNT*REQUESTS_PER_THREAD} requests completed in #{Time.now - start} seconds" Clifford Heath.