From: Eric Jensen Date: 2009-11-18T10:07:40+09:00 Subject: Re: Asynchronous http POST? I'm not sure why ruby doesn't provide the ability to send the request without reading the response, but it's fairly trivial to split the Net::HTTP.request method into two halves to do so, as per below: require 'net/http' module Net class HTTP < Protocol # pasted first half of HTTP.request that writes the request to the server, # does not return HTTPResponse and does not take a block def request_async(req, body = nil) if proxy_user() unless use_ssl? req.proxy_basic_auth proxy_user(), proxy_pass() end end req.set_body_internal body begin_transport req req.exec @socket, @curr_http_version, edit_path(req.path) end # second half of HTTP.request that yields or returns the response def read_response(req, body = nil, &block) # :yield: +response+ begin res = HTTPResponse.read_new(@socket) end while res.kind_of?(HTTPContinue) res.reading_body(@socket, req.response_body_permitted?) { yield res if block_given? } end_transport req, res res end end end # Example usage for a non-blocking GET without following redirects: http = Net::HTTP.new('www.google.com') req = Net::HTTP::Get.new('/') http.start begin http.request_async(req) # do other stuff res = http.read_response(req) ensure http.finish end res.value # raise if error p res.body -- Posted via http://www.ruby-forum.com/.