excon rest-client gem .
, rest-client - multipart/form-data excon, .
, .
require 'excon'
require 'rest-client'
streamer = lambda do |chunk, remaining_bytes, total_bytes|
puts "Remaining: #{remaining_bytes.to_f / total_bytes}%"
puts RestClient.post('http://posttestserver.com/post.php', :param1 => chunk)
end
Excon.get('http://textfiles.com/computers/ami-chts.txt', :response_block => streamer)
, ( , , . , , http )
require 'excon'
require 'uri'
require 'net/http'
class Producer
def initialize
@mutex = Mutex.new
@body = ''
end
def read(size, out=nil)
length = nil
@mutex.synchronize {
length = @body.slice!(0,size)
}
return nil if length.nil? || length.empty?
out << length if out
length
end
def produce(str)
@mutex.synchronize {
@body << str
}
end
end
@stream = Producer.new
uri = URI("yourpostaddresshere")
conn = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new uri.request_uri, {'Transfer-Encoding' => 'chunked', 'content-type' => 'text/plain'}
request.body_stream = @stream
Thread.new {
streamer = lambda do |chunk, remaining_bytes, total_bytes|
@stream.produce(chunk)
end
Excon.get('http://textfiles.com/computers/ami-chts.txt', :response_block => streamer)
}
conn.start do |http|
http.request(request)
end
, , HTTP.start (Ruby Net: HTTP change).