Mus Mus - 2 years ago 645
Android Question

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

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: -

<notes>Test api support</notes>
<project_id type="integer">3</project_id>
<task_id type="integer">14</task_id>
<spent_at type="date">Tue, 17 Oct 2006</spent_at>

As per the documentation, I tried doing it using
, but it is failing. Is this any other way to do it? I can POST equivalent JSON too. Any ideas?

Answer Source

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");, params, responseHandler);

To post JSON:

JSONObject jsonParams = new JSONObject();
jsonParams.put("notes", "Test api support");
StringEntity entity = new StringEntity(jsonParams.toString());, restApiUrl, entity, "application/json",
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download