Get the exact size of the download package from the download address

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.