httpclient3可以通过MultipartRequestEntity实现多文件同时上传,httpclient4找不到这个类了,也没有发现类似的方法。请问在httpclient4怎么实现多文件上传。
------解决方案--------------------
request = new HttpPost(url);
MultipartEntity me=new MultipartEntity();
if(parameter!=null&¶meter.size()>0){
Iterator<Entry<String, Object>> strings= parameter.entrySet().iterator();
while(strings.hasNext()){
Entry<String,Object> entry= strings.next();
String key=entry.getKey();
Object value=entry.getValue();
if(value instanceof FileBody){
me.addPart(key, (ContentBody) value);
}else{
me.addPart(key, new StringBody(value.toString(),Charset.forName("utf-8")));
}
/*
if(value instanceof FileModel){//如果传进来的是文件
FileModel fileMode=(FileModel) value;
File targetFile=new File(fileMode.filePath);
if(targetFile.exists())
{
me.addPart("imgData", new FileBody(targetFile,"image/jpeg","utf-8"));
}
}else
{
me.addPart(key, new StringBody(value.toString(),Charset.forName("utf-8")));
}
*/
}
}
request.setEntity(me);
request.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout);
request.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,readTimeout);
//httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
if(BuildConfig.DEBUG){
Log.d(tag, "post url:"+url);
}
HttpResponse response=httpClient.execute(request);
int statusCode=response.getStatusLine().getStatusCode();
//int statusCode = response.getStatusLine().getStatusCode();