简体   繁体   English

泽西岛HTTP客户

[英]Jersey http client

I'm using jersey http client to send requests to some remote API. 我正在使用jersey http客户端将请求发送到某些远程API。 I need to measure how much time does it take to send request to the server and wait until it gets processed and server returns me some status code. 我需要测量将请求发送到服务器并等待它得到处理以及服务器向我返回一些状态代码需要花费多少时间。 Is there a way how I can do it with jersey? 有没有办法让我穿球衣? Here is my code of post method: 这是我的post方法代码:

  public Response post(String targetUrl, Entity entity)
  {
    return client.target(targetUrl)
        .request()
        .accept(MediaType.APPLICATION_JSON_TYPE)
        .header(SERVER_AUTH, true)
        .post(entity);
  }

Actually, it was my fault. 其实这是我的错。 By default, this client is synchronized so it blocks thread until response is received. 默认情况下,此客户端是同步的,因此它将阻塞线程,直到收到响应为止。 But my problem was that URL was incorrect and code immediately returned status 'Resouce not found.' 但是我的问题是URL不正确,代码立即返回状态“找不到资源”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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