How could I get two urls by the same request in Ruby? -


i want contents of 'a.com/a.html' , 'a.com/b.html' same request , code is

uri = uri.parse("http://www.sample.com/sample1.html")   http = net::http.new(uri.host, uri.port)   request = net::http::get.new(uri.request_uri)   # request.initialize_http_header({"user-agent" => "mozilla/5.0 (macintosh; intel mac os x     10_8_4) applewebkit/537.36 (khtml, gecko) chrome/28.0.1500.95 safari/537.36"})  result = http.request(request).body 

should change path of request?or other idea?

you can't fetch multiple resources @ once, can reuse http connection fetch multiple resources same server (one after another):

require 'net/http'  net::http.start('a.com') |http|   result_a = http.get('/a.html').body   result_b = http.get('/b.html').body end 

from docs:

::start creates connection http server kept open duration of block. connection remain open multiple requests in block if server indicates supports persistent connections.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -