【问题标题】:Unexpected HTTP 404 when running Request.Get() after a Post()在 Post() 之后运行 Request.Get() 时出现意外的 HTTP 404
【发布时间】:2015-10-29 03:06:48
【问题描述】:

在使用来自 apache httpclient 的 Fluent API 时,有没有办法隔离 HTTP 连接以防止出现以下行为?

我有一些使用 Fluent API 进行 Gets 和 Posts 的 junit 测试。

当我单独运行 junit 测试时,我得到了预期的结果。 Test1: Request.Post(https://host:port/xxx") HTTP 200 Test2: Request.Get(https://host:port/yyy") HTTP 200

当我在我的测试套件中运行 junit 测试时,我得到了不正确的结果。 Test1: Request.Post(https://host:port/xxx") HTTP 200 Test2: Request.Get(https://host:port/yyy") HTTP 404

【问题讨论】:

    标签: junit4 apache-httpclient-4.x fluent


    【解决方案1】:

    为了解决这个问题,我为每条路由使用了带有执行器的 HttpClient。

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    Executor xxxExecutor = Executor.newInstance(httpClientBuilder.build());
    Executor yyyExecutor = Executor.newInstance(httpClientBuilder.build());
    
    xxxExecutor.execute(Request.Post(https://host:port/xxx"))...
    yyyExecutor.execute(Request.Get(https://host:port/yyy"))...
    

    【讨论】:

      猜你喜欢
      • 2017-06-23
      • 2021-12-10
      • 1970-01-01
      • 2021-01-21
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      相关资源
      最近更新 更多