Android 文件上传 使用AsyncHttpClient开源框架
public void upload(View view) { AsyncHttpClient client = new AsyncHttpClient(); RequestParams requestParams = new RequestParams(); File file = new File("/sdcard/NTUSER.DAT.LOG"); try { requestParams.put("file", file); } catch (FileNotFoundException e) { } client.post("http://10.0.2.2:8080/FileUploadServlet", requestParams, new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT).show(); } }); }
我这里服务器用的是tomcat,commons-fileupload工具
本文出自 无忧之路 - 博客园