2

I'm using the loopj library (https://github.com/loopj/android-async-http) and it's recently changed to be compatible with API 23.

When submitting a 'put' request I would pass the StringEntity into the put method like so:

client.put(CallApplication.getContext(),url, request.StringEntity, responseHandler);

My StringEntity is an object that's converted into Json by doing:

public static StringEntity getJsonFromObject(Object object) {

    String json = new Gson().toJson(object);
    StringEntity stringEntity = null;
    try {
        stringEntity = new StringEntity(json, HTTP.UTF_8);
        stringEntity.setContentType("text/json");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return stringEntity;
}

Now I need to use HttpEntity instead and it's not clear how I can get it. How can I get my json string into the HttpEntity?

Mykola
  • 3,343
  • 6
  • 23
  • 39
Murphybro2
  • 2,207
  • 1
  • 22
  • 36

2 Answers2

1

As it happens there is a

cz.msebera.android.httpclient.entity.StringEntity

available to use. Who knew!

Cheers anyway

Murphybro2
  • 2,207
  • 1
  • 22
  • 36
0

You can add namevalue pair to set entity

ArrayList nvp= new ArrayList(); nvp.add(new BasicNameValuePair("keyname", jsonvalue));

client.setEntity(new UrlEncodedFormEntity(nvp));

koutuk
  • 832
  • 1
  • 8
  • 17
  • setEntity method doesnt exist – Murphybro2 Jan 04 '16 at 12:40
  • public RequestHandle get(Context context, String url, HttpEntity entity, String contentType, ResponseHandlerInterface responseHandler) { return sendRequest(httpClient, httpContext, addEntityToRequestBase(new HttpGet(URI.create(url).normalize()), entity), contentType, responseHandler, context); } your client contain this method can you try to call this – koutuk Jan 04 '16 at 12:50
  • create seperate object of Httpentity – koutuk Jan 04 '16 at 12:51