POSTing JSON/XML using android-async-http (loopj)

前端 未结 9 790
广开言路
广开言路 2020-12-02 07:01

I am using android-async-http and really liking it. I\'ve run into a problem with POSTing data. I have to post data to the API in the following format: -

&l         


        
9条回答
  •  温柔的废话
    2020-12-02 07:37

    Loopj POST examples - extended from their Twitter example:

    private static AsyncHttpClient client = new AsyncHttpClient();
    

    To post normally via RequestParams:

    RequestParams params = new RequestParams();
    params.put("notes", "Test api support"); 
    client.post(restApiUrl, params, responseHandler);
    

    To post JSON:

    JSONObject jsonParams = new JSONObject();
    jsonParams.put("notes", "Test api support");
    StringEntity entity = new StringEntity(jsonParams.toString());
    client.post(context, restApiUrl, entity, "application/json",
        responseHandler);
    

提交回复
热议问题