1

/** 
     * 获取response header中Content-Disposition中的filename值 
     * @param response
     * @return 
     */
    private static String getFileName(HttpResponse response) {  
        Header contentHeader = response.getFirstHeader("Content-Disposition");  
        String filename = null;  
        if (contentHeader != null) {  
            HeaderElement[] values = contentHeader.getElements();  
            if (values.length == 1) {  
                NameValuePair param = values[0].getParameterByName("filename");  
                if (param != null) {  
                    try {
                    //此处根据具体编码来设置
                        filename = new String(param.getValue().toString().getBytes("ISO-8859-1"), "GBK");  
                    } catch (Exception e) {  
                        e.printStackTrace();  
                    }  
                }  
            }  
        }
        return filename;  
    }
————————————————
版权声明:本文为CSDN博主「_Google_」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u014639010/article/details/80566471

posted @ 2021-03-25 19:53  北海的鲸鱼  阅读(15)  评论(0)    收藏  举报