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工具

posted @ 2013-11-17 16:46  无忧之路  阅读(1623)  评论(0编辑  收藏  举报
无忧之路