2013-11-26 69 views
0

我有MIME作爲字符串和httpheader我怎樣才能從http頭獲得擴展名的文件名或簡單地說有沒有什麼辦法從MIME中獲得擴展名?帶有MIME字符串擴展名的文件名

如: MIME,Extension

`application/octet-stream class` 
`application/octet-stream dms` 
` application/octet-stream exe` 
`application/octet-stream lha` 

以上具有相同的MIME字符串,但不同的擴展

這些都是我從httpHeader得到一個zip文件

Keep-Alive : timeout=10 

Connection : Keep-Alive 

Age : 4418 

Accept-Ranges : bytes 

ETag : "ee0043-157f-4acf6ff5c1640" 

Cache-Control : max-age=10800, s-maxage=10800 

x-mii-cache-hit : 1 

X-Pb-Mii : Powered by Mirror Image Internet 

Via : 1.1 sjc005158 (MII-APC/2.3), 1.1 sjc005112 (MII-APC/2.3) 

Content-Length : 5503 

Last-Modified : Thu, 15 Sep 2011 08:52:33 GMT 

Date : Tue, 26 Nov 2013 08:30:27 GMT 

Content-Type : application/zip 

Server : MII-APC/2.4.5 

回答

1

我猜的東西你可以,如果你真的想使用像this這樣的列表,但也許這不是最好的方法。

另一種方法是使用Content Disposition頭(如果可用):

Content-Disposition: attachment; filename=Myfile.txt 

然後從那裏

+0

我知道的第一種方式解析文件名和擴展名,那裏有重複的,因爲我在問題中提到。 。我沒有在標題中得到這些東西 –

+0

如何解析URL以獲取文件名和擴展名? – gmanolache

+0

可能沒有文件名或擴展名 –