私はレトロフィットを使用していますが、セッション 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 拡張機能なし) を使用してこれを行うより良い方法はありますか?