简体   繁体   中英

Associating responses with specific requests using Loopj Android Asynchronous Http Client

I'm using The Loopj Android Asynchronous HTTP Client to send multiple HTTP requests asynchronously.

I'm using a static AsyncHttpClient as suggested and sending multiple HTTP posts and receiving responses on an anonymous class. The problem is that when a request comes back I don't know how to tie it back to the original request.

For instance, in a caching situation, when I send a post and receive a 200 OK I need to be able to know which request that response is for so I can mark it as successfully sent.

Try this:

public class MyAsyncHttpResponseHandler extends AsyncHttpResponseHandler {

    private String requestId;

    public AsyncHttpResponseHandler(String requestId) {
        this.requestId = requestId;
    }

    @Override
    public void onSuccess(String arg0)
    {
        super.onSuccess(arg0);
        // Use requestId here
    }
}

Sending request:

client.get(url, new MyAsyncHttpResponseHandler(requestId))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM