伙计们,我正在使用改造,我想知道如何透明地处理会话 cookie。为此,我扩展了给定的 ApacheClient 并在对 ApacheClient.execute(HttpClient, HttpUriRequest) 的自定义调用中使用 CookieStore :
Client client = new ApacheClient() {
final CookieStore cookieStore = new BasicCookieStore();
@Override
protected HttpResponse execute(HttpClient client, HttpUriRequest request) throws IOException {
// BasicHttpContext is not thread safe
// CookieStore is thread safe
BasicHttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
return client.execute(request, httpContext);
}
};
RestAdapter restAdapter = new RestAdapter.Builder()
.setServer(API_URL)
.setClient(client)
.build();
有没有更好的方法来使用内置的改造 API(没有 HttpClient 扩展)?