AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("key", value);
client.post(context, URL_YOURURL,
params, new AsyncHttpResponseHandler() {
Progress pd = new Progress(context);
public void onStart() {
super.onStart();
pd.show();
}
@Override
public void onSuccess(int arg0,
Header[] arg1, byte[] arg2) {
try {
JSONObject json = new JSONObject(
new String(arg2));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onFailure(int arg0,
Header[] arg1, byte[] arg2,
Throwable arg3) {
}
public void onFinish() {
super.onFinish();
if(pd!=null){
pd.dismiss();
}
}
});
}
I think You are asking for this example.
//entity
JSONObject jsonObject = new JSONObject();
StringEntity entity;
try {
jsonObject.put("suggestion", suggestion);
entity = new StringEntity(jsonObject.toString());
//url
String url = "user/feedback?";
YXUser yxUser = YXUser.currentUser();
//公司id
if (yxUser != null && yxUser.getCompanyId() != null) {
url = url + "company_id=" + yxUser.getCompanyId();
}
if (null != YXPersistence.getValueByKey(AppConstant.APP_TOKEN_KEY)) {
url = url + "&access_token=" + YXPersistence.getValueByKey(AppConstant.APP_TOKEN_KEY);
}
url = AppConstant.BASE_URL + url;
client.post(this, url, entity, "application/json", new MyHttpResponseHandler(this) {
@Override
protected void onNormalResponse(int statusCode, Header[] headers, JSONObject info) {
if (JSONUtil.checkStatusSuccess(info)) {
showToast("上传成功");
finish();
}
}
});
} catch (JSONException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}