【问题标题】:How save cookie between request in asyncHttpClient?如何在 asyncHttpClient 中的请求之间保存 cookie?
【发布时间】:2015-04-29 08:48:34
【问题描述】:

我发送了两个请求,我想使用 cookie 进行第二个请求(来自第一个请求的响应的 cookie)。

现在如何运作:

Future<Response> f = asyncHttpClient
    .prepareGet(URL_1)
    .execute();
Response r = f.get();

/* I want code without saving and restoring cookie */
List<Cookie> cookies = r.getCookies();
AsyncHttpClient.BoundRequestBuilder b = asyncHttpClient.prepareGet(URL_2)
for (Cookie c : cookies) {
  b.addCookie(c);
}

f = b.execute();
r = f.get();

我想删除复杂的代码,我该怎么做

【问题讨论】:

    标签: java httprequest asynchttpclient


    【解决方案1】:

    如果您已经在使用Java8,那么ComparableFuture 可以帮助您处理请求顺序运行。否则,您可以找到有用的RxJava 第三方(链接到RxJava 在文章摘要中)。

    【讨论】:

    猜你喜欢
    • 2021-02-22
    • 2015-08-25
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 2011-10-26
    • 2016-07-02
    相关资源
    最近更新 更多