AsyncHttpClient文件上传

来源:互联网 发布:淘宝退货售后卡怎么写 编辑:程序博客网 时间:2024/05/17 06:11
public void click(View view) throws FileNotFoundException{String url = "http://192.168.1.104:8080/day18/servlet/UploadServlet3";String path = et_path.getText().toString().trim();File file = new File("/sdcard/psbe.jpg");if(file.exists() && file.length()>0){AsyncHttpClient client = new AsyncHttpClient();RequestParams params = new RequestParams();    params.put("profile_picture", new File(path)); // Upload a Fileclient.post(url, params,new AsyncHttpResponseHandler() {@Overridepublic void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {// TODO Auto-generated method stubToast.makeText(MainActivity.this,"上传成功",1).show();}@Overridepublic void onFailure(int statusCode, Header[] headers,byte[] responseBody, Throwable error) {// TODO Auto-generated method stubToast.makeText(MainActivity.this,"上传失败",1).show();}});}else{Toast.makeText(this,"路径错误",1).show();}}

0 0