通过执行POST JSON / XML Android的异步HTTP(循环J) [英] POSTing JSON/XML using android-async-http (loopj)
本文介绍了通过执行POST JSON / XML Android的异步HTTP(循环J)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 Android的异步HTTP ,并真正喜欢它。我碰到的与发送的数据有问题。我要发布数据到API中的格式如下: -
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: -
<request>
<notes>Test api support</notes>
<hours>3</hours>
<project_id type="integer">3</project_id>
<task_id type="integer">14</task_id>
<spent_at type="date">Tue, 17 Oct 2006</spent_at>
</request>
根据文件,我试图做它用 RequestParams
,但它是失败的。这是任何其他的方式来做到这一点?我可以张贴相当于JSON了。任何想法?
As per the documentation, I tried doing it using RequestParams
, but it is failing. Is this any other way to do it? I can POST equivalent JSON too. Any ideas?
推荐答案
循环J后例子 - 从他们的微博为例延长
Loopj post examples - extended from their Twitter example
private static AsyncHttpClient client = new AsyncHttpClient();
要通过正常后RequestParams
To post normally via RequestParams
RequestParams params = new RequestParams();
params.put("notes", "Test api support");
client.post(restApiUrl, params, responseHandler);
要张贴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);
这篇关于通过执行POST JSON / XML Android的异步HTTP(循环J)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文