java http 手機瀏覽器下載word文檔失敗的問題

一開始設置的Content-type爲:

response.addHeader("Content-type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.addHeader("Content-disposition", "attachment;filename=" +  URLEncoder.encode(fileName, "UTF-8"));

結果在手機瀏覽器下載docx文檔時,能出現下載任務,但是下載總是失敗。

後來嘗試將Content-type改爲如下形式:

response.addHeader("Content-type", "application/x-msdownload");
response.addHeader("Content-disposition", "attachment;filename=" +  URLEncoder.encode(fileName, "UTF-8"));

改完之後就可以成功下載word文檔了。

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章