带主体的android异步http post请求 这需要实现一个功能,用户可以在应用程序中向服务器发送反馈。我在应用程序中使用asynchttpclient。但是我不知道怎么做。任何人都知道怎么做请告诉我,非常感谢。

带主体的android异步http post请求 这需要实现一个功能,用户可以在应用程序中向服务器发送反馈。我在应用程序中使用asynchttpclient。但是我不知道怎么做。任何人都知道怎么做请告诉我,非常感谢。,android,post,android-async-http,Android,Post,Android Async Http,以下是要求: 将post请求与正文一起使用(有一个参数建议内容) api:api/用户/反馈?公司标识=&访问令牌= 在检查asynchttpclient的post方法时,我发现了以下方法: 公共请求句柄post(字符串url,responseHandler接口responseHandler){ 返回帖子(null,url,null,responseHandler); } 我想你是在问这个例子 //entity JSONObject jsonObject = new JSONObject

以下是要求:

  • 将post请求与正文一起使用(有一个参数建议内容)
  • api:api/用户/反馈?公司标识=&访问令牌=
  • 在检查asynchttpclient的post方法时,我发现了以下方法: 公共请求句柄post(字符串url,responseHandler接口responseHandler){ 返回帖子(null,url,null,responseHandler); }

    我想你是在问这个例子

    //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();
        }
    
        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();
                        }
    
    
    
                    }
                });
    
    
    }
    
    //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();
        }