使用开源框架AsyncHttpClient进行Json的Post请求
·
我们在使用AsyncHttpClient的时候,可能很多人就直接是下面的用法
RequestParams params = new RequestParams();
params.put("username", userName);
params.put("userpass", userPass);
我一开始也是这么做的,但是发现这样子得到的并不是我想要发送的形式。上网一搜以后发现如下方法`
`
try {
jsonObject.put("username", userName);
jsonObject.put("userpass", userPass);
StringEntity stringEntity = null;
stringEntity = new StringEntity(jsonObject.toString());
} catch (Exception e1) {
e1.printStackTrace();
}
AsyncHttpClient client = new AsyncHttpClient();
client.post(context,url,stringEntity,"application/json"new JsonHttpResponseHandler(){.......
这样就解决了发送Json数据的问题了。
更多推荐
所有评论(0)