关于httpclient上传文件是中文名称的处理

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

在一个项目中,上传文件采用httpclient来post文件,在测试中发现 如果文件是中文名称,上传的文件是乱码

经过跟踪发现,原来在httpclient中进行了编码,为ASCII,所以为乱码

org\apache\commons\httpclient\util包下EncodingUtil.java

/**

* Converts the specified string to byte array of ASCII characters.

*

* @param data the string to be encoded

* @return The string as a byte array.

*

* @since 3.0

*/

public static byte[] getAsciiBytes(final String data) {

if (data == null) {

throw new IllegalArgumentException("Parameter may not be null");

}

try {

return data.getBytes("US-ASCII");

} catch (UnsupportedEncodingException e) {

throw new HttpClientError("HttpClient requires ASCII support");

}

}

解决方法:

1 在接收端处理ascii数据

2 重新编译httpclient包,即更改上面的方法 ,改为iso8859-1或utf-8

这样可以解决中文的问题

采用httpclient是一个很好的方法,可以给你其他的系统post数据,好像delphi中的indy控件,

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航