0

I am trying to send data via post method of AsyncHttpClient in json format to server, server accept this format

{
  email : 'foo@bar.com'
  password:'xxxxxx'
  'username:'John Doe'
  'lastname:'john'
}

and this is my code

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);

when I log the entity the result is shown as below

[Content-Type: text/plain; charset=ISO-8859-1,Content-Length: 496,Chunked: false]

please help me?

Iamat8
  • 3,888
  • 9
  • 25
  • 35
Matiullah Karimi
  • 1,234
  • 1
  • 15
  • 17

2 Answers2

1

I also use this AsyncHttpClient

the way i send json data is

   // 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() {

Which works fine for me.. hope this will help..

Sanoop Surendran
  • 3,484
  • 4
  • 28
  • 49
0

JSON format needs to complete the conversion server, the client only needs to be one by one in the http-body can be.

liuzx
  • 1