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

在一个项目中,上传文件采用httpclient来post文件,在测试中发现如果文件是中文名称,上传的文件是乱码
经过跟踪发现,原来在httpclient中进行了编码,为ASCII,所以为乱码
org\apache\commons\httpclient\util包下EncodingUtil.Java

/**
*ConvertsthespecifiedstringtobytearrayofASCIIcharacters.
*
*@paramdatathestringtobeencoded
*@returnThestringasabytearray.
*
*@since3.0
*/
publicstaticbyte[]getAsciiBytes(finalStringdata){

if(data==null){
thrownewIllegalArgumentException("Parametermaynotbenull");
}

try{
returndata.getBytes("US-ASCII");
}catch(UnsupportedEncodingExceptione){
thrownewHttpClientError("HttpClientrequiresASCIIsupport");
}
}

解决方法:
1在接收端处理ascii数据
2重新编译httpclient包,即更改上面的方法,改为iso8859-1或utf-8
这样可以解决中文的问题

50校招生网 http://www.50xiao.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值