关于AsyncHttpClient框架的post 提交表单上传文件怎么弄

安静的码字猴 2016-06-01 04:15:34


上传多图的字段名是img[],我不明白 到底怎么给服务器上传啊,

AsyncHttpClient 有三种形式的post提交数据方法,但是Header[]这个对象怎么获取到?(第一次以提交表单形式上传多图)

public static RequestHandle post(Context context, String url, Header[] headers, HttpEntity entity, String contentType, AsyncHttpResponseHandler responseHandler){
RequestHandle requestHandle = client.post(context, url, headers, entity, contentType, responseHandler);
return requestHandle;
}

public static RequestHandle post(Context context, String url, HttpEntity entity, String contentType, AsyncHttpResponseHandler responseHandler){
RequestHandle requestHandle = client.post(context, url, entity, contentType, responseHandler);
return requestHandle;
}

public static RequestHandle post(Context context, String url, Header[] headers, RequestParams params, String contentType, AsyncHttpResponseHandler responseHandler){
RequestHandle requestHandle = client.post(context,url,headers,params,contentType,responseHandler);
return requestHandle;
}

...全文
346 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
adorable_xu 2016-06-15
  • 打赏
  • 举报
回复
AsyncHttpClient client = new AsyncHttpClient(); client.setTimeout(6 * 1000); RequestParams params = new RequestParams(); if (Bimp.tempSelectBitmap.size() > 0) { for(int i = 0; i < Bimp.tempSelectBitmap.size(); i++) { //图片路径 if(i != Bimp.tempSelectBitmap.size() - 1) { picpath = (Bimp.tempSelectBitmap.get(i).getImagePath() + "&&&&&"); } else { picpath = Bimp.tempSelectBitmap.get(i).getImagePath(); } try { params.put("img", new File(picpath)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } client.post(mUrl, params, new AsyncHttpResponseHandler() { // 请求成功 @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { // TODO Auto-generated method stub Toast.makeText(getActivity(), "上传成功", Toast.LENGTH_SHORT).show();

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧