do |http| http.post(uri.path, URI.encode_www_form(params)) end 1. parse the URL string 2. determine whether we need to use SSL 3. open the TCP connection 4. encode the post parameters 5. send the request
response.body.to_s # reads whole response body # or response.body.readpartial # reads first chunk response.body.readpartial # reads next chunk # or response.body.each { |chunk| … } # yields chunks response = HTTP.get("http://example.com/export.csv") # reading headers before download fail "too large" if response.content_length > max_size # streaming download to disk File.open("export.csv", "w") do |file| response.body.each do |chunk| file.write(chunk) end end