How can i download a file without file name and file extension in the url

前端 未结 3 657
北恋
北恋 2021-01-27 00:14

My problem is that I dont Know how i can download a File withknowing the file name or the file extension in the url, like this http://findicons.com/icon/download/235456/internet

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-27 00:52

    I've had a hard time solving this issue myself and have come to a solution solving some issues in relation of obtaining the file name automatically.

    Some headers does not include the Content Disposition as suggested in https://stackoverflow.com/a/37228939/8805908, but the ones that do is still used.

    I was wondering how Chrome, firefox etc. could obtain the name of the file though this information is not available through any header entry. I found that the links left without the information could be derived via its URL, from which i am using the code of:

    http://codesnippets.fesslersoft.de/how-to-get-the-filename-of-url-in-c-and-vb-net/

    My conclusion so far is; check the header for Content Disposition, if this does not contain any information check the URL for any file matches. So far I have not found a download link that I have not been able to retrieve the file name of.

    I hope this may solve some issues.

    --- Edit 12-06-2018

    The solution using these methods are satisfying the following links: 5 test cases

提交回复
热议问题