0

I am using StringEntity with AndroidAsyncHttp but it is deprecated. Is there another way to get this to work while sending my json string in the way I am to my web service?

public void getPropertyImagesAsync(final String[] params) {
    JsonStructure jsonStructure = new JsonStructure();
    jsonStructure.methodName = "getPropertyWorkorders";
    jsonStructure.serviceName = "mobileapi";
    jsonStructure.parameters = params;

    String jsonString = new Gson().toJson(jsonStructure);

    StringEntity entity = null;
    try {
        entity = new StringEntity(jsonString);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    AsyncHttpClient client = new AsyncHttpClient();
    client.post(visnetawrap, BASE_URL + "/amf/gateway/?contentType=application/json", entity, "application/json", new TextHttpResponseHandler() {
        @Override
        public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
            AppUtils.outputJsonString(s);
        }

        @Override
        public void onSuccess(int i, Header[] headers, String s) {
            AppUtils.outputJsonString(s);
        }
    });
}
Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
Joe Ginley
  • 301
  • 3
  • 15

2 Answers2

0

Keep an eye on the situation, but you can probably get away with continuing to use StringEntity for now.

StringEntity is actually part of Apache HTTP, not android-async-http. Google deprecated the entire Apache HTTP API in SDK 22, and removed it from the stub library in SDK 23 (M preview). It reportedly still runs on M devices, but you can't compile it.

Unfortunately, android-async-http was designed around Apache HTTP. Worse, it exposes its use of that API, so it can't be changed without causing breakage. The developers have announced plans to ensure continued support, possibly by introducing a dependency on the standalone Apache HTTP.

Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
0

I recommend you to use a library for your network operations. You can use Retrofit. It's a powerful library and easy to use.

http://square.github.io/retrofit/

savepopulation
  • 11,736
  • 4
  • 55
  • 80