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

前端 未结 9 787
广开言路
广开言路 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:29

    @Timothy answer did not work for me.

    I defined the Content-Type of the StringEntity to make it work:

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

    Good Luck :)

提交回复
热议问题