Http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html#method-i-headHead(path, Initheader = nil)Click to toggle source
Gets only the header from the path connected-to host. Is header a Hash like {' Accept ' + = '/', ...}.
This method returns a Net::httpresponse object.
This method is never raises an exception.
Response = Nilnet::http.start (' some.www.server ', +) {|http| = Http.head ('/index.html ')}p response[' Content-type ']
So there is such a wonderful method, welcome to shoot Bricks
def self.get_the_package_size Origin_urlifOrigin_url.present?ifOrigin_url.index (". com") Array= Origin_url.split (". com"). Reverse Url_end= Array[0] Url_begin= Array[1].split ("//") [1] Url_begin= "#{url_begin}.com"elsif Origin_url.index (". Net") Array= Origin_url.split (". NET"). Reverse Url_end= Array[0] Url_begin= Array[1].split ("//") [1] Url_begin= "#{url_begin}.net"Else return""End Response=Nil Net::http.start (Url_begin,"10.103.11.54", Bayi) {|http|Response=http.head (url_end)}returnresponse[' Content-length '] End End
Actually, you can just take a look at the command.
Curl-v-xhead http://dl.g.youku.com/20150317/1426557582_XXXX-20150312.apk
By getting the exact size of the download package