0

Good day,

In this moment I'm developing an app that use a webservice of mode Async, but I have some problems with it. I need use the webservice of mode synchronous for continue with my principal thread without any problem.

Thanks so much!!!

Rancid
  • 3
  • 2
  • Welcome to StackOverflow, please read ["How do I ask a good question?"](http://stackoverflow.com/help/how-to-ask) – yvesmancera Aug 20 '15 at 16:40

1 Answers1

0

Same way as we use async-http-client for loopj, but it will block the UI till completion.

SyncHttpClient syncHttpClient = new SyncHttpClient();
syncHttpClient.setTimeout(timeout);
syncHttpClient.post(url, params, responseHandler);

syncHttpClient .post("http://example.com", params, new JsonHttpResponseHandler() {
        @Override
        public void onStart() {
            // you can do something here before request starts                    
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            // success logic here
        }


        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONObject errorResponse) {
           // handle failure here
        }

    });
Vishal Raj
  • 1,755
  • 2
  • 16
  • 35