public void click(View view) { AsyncHttpClient client = new AsyncHttpClient(); try { String url = "http://url?name=" + URLEncoder.encode("aaa", "utf-8") + "&pass=" + URLEncoder.encode("bbb", "utf-8"); client.get(url, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { super.onSuccess(statusCode, headers, responseBody); Toast.makeText(Main.this, "请求成功" + new String(responseBody), 0).show(); } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { // TODO Auto-generated method stub super.onFailure(statusCode, headers, responseBody, error); } }); } catch (Exception e) { } } public void postclick(View view) { try { AsyncHttpClient client = new AsyncHttpClient(); String url = "http://url"; RequestParams params = new RequestParams(); params.put("name", "张三"); params.put("pass", "123456"); client.post(url, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { super.onSuccess(statusCode, headers, responseBody); Toast.makeText(Main.this, "请求成功" + new String(responseBody), 0).show(); } }); } catch (Exception e) { // TODO: handle exception } } public void btnupfile(View view) { AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); try { File file = new File("/sdcard/1.jpg"); System.out.println(file); params.put("pic", file); client.post("http://url", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { super.onSuccess(statusCode, headers, responseBody); Toast.makeText(Main.this, "上传文件成功!", 0).show(); } }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }