使用开源的框架async_http_client发送post请求

淳于亦
2023-12-01
String path = "http://192.168.1.100:8080/login";
AsyncHttpClient client = new AsyncHttpClient();

RequestParams params = new RequestParams();

// number=123&pwd=123
params.add("number", number);
params.add("pwd", pwd);

client.post(path, params, new AsyncHttpResponseHandler(){
@Override
public void onSuccess(int statusCode, Header[] headers,
byte[] responseBody) {
tv.setText(new String(responseBody));
}


@Override
public void onFailure(int statusCode, Header[] headers,
byte[] responseBody, Throwable error) {
error.printStackTrace(System.out);
Toast.makeText(MainActivity.this, "erro~~~ ", 0).show();
}

});

}
 类似资料: