我试图通过json格式的AsyncHttpClient的post方法向服务器发送数据,服务器接受这种格式
{
email : 'foo@bar.com'
password:'xxxxxx'
'username:'John Doe'
'lastname:'john'
}
这是我的代码
JSONObject params = new JSONObject();
params.put("last_name","Karimi");
params.put("username","zahid");
params.put("email","zahid.omerzad@gmail.com");
params.put("password","1234566");
StringEntity entity = new StringEntity(params.toString());
Log.d("entity3",entity+"");
String url = "http://192.168.100.12/users";
client.post(context, url, entity, "application/json", handler);
当我记录实体时,结果显示如下
[Content-Type: text/plain; charset=ISO-8859-1,Content-Length: 496,Chunked: false]
请帮帮我?
答案 0 :(得分:1)
我也使用此AsyncHttpClient
我发送json数据的方式是
// postData = your json data
ByteArrayEntity entity = null;
try {
entity = new ByteArrayEntity(postData.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
asyncHttpClient.post(getActivity(), url, entity, "application/json", new AsyncHttpResponseHandler() {
哪个适用于我..希望这会有所帮助..
答案 1 :(得分:0)