asynchronous http request in ruby

后端 未结 3 1608
情深已故
情深已故 2020-12-05 17:51
 require \'net/http\'

urls = [
  {\'link\' => \'http://www.google.com/\'},
  {\'link\' => \'http://www.facebook.com/\'},
 {\'link\' => \'http://www.yahoo.c         


        
3条回答
  •  [愿得一人]
    2020-12-05 18:00

    If its just about plain http requests in async style, probably Unirest is the best fit to achieve it.

    Asnc request is as simple as:

    response = Unirest.post "http://httpbin.org/post", 
                        headers:{ "Accept" => "application/json" }, 
                        parameters:{ :age => 23, :foo => "bar" } {|response|
    response.code # Status code
    response.headers # Response headers
    response.body # Parsed body
    response.raw_body # Unparsed body
    }
    

提交回复
热议问题