com.ning.http.client.Response.getResponseBodyExcerpt()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中com.ning.http.client.Response.getResponseBodyExcerpt方法的一些代码示例,展示了Response.getResponseBodyExcerpt的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getResponseBodyExcerpt方法的具体详情如下:
包路径:com.ning.http.client.Response
类名称:Response
方法名:getResponseBodyExcerpt

Response.getResponseBodyExcerpt介绍

[英]Returns the first maxLength bytes of the response body as a string. Note that this does not check whether the content type is actually a textual one, but it will use the charset if present in the content type header.
[中]以字符串形式返回响应正文的第一个maxLength字节。请注意,这不会检查内容类型是否实际上是文本类型,但如果内容类型标头中存在字符集,它将使用该字符集。

代码示例

代码示例来源:origin: com.ning/async-http-client

public String getResponseBodyExcerpt(int maxLength) throws IOException {
  return response.getResponseBodyExcerpt(maxLength);
}

代码示例来源:origin: com.ning/async-http-client

public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException {
  return response.getResponseBodyExcerpt(maxLength, charset);
}

代码示例来源:origin: HubSpot/Singularity

@Override
public Response onCompleted(Response response) throws Exception {
 Optional<String> responseBody = Optional.absent();
 if (response.hasResponseBody()) {
  responseBody = Optional.of(response.getResponseBodyExcerpt(maxHealthcheckResponseBodyBytes));
 }
 saveResult(Optional.of(response.getStatusCode()), responseBody, Optional.<String> absent(), Optional.<Throwable>absent());
 return response;
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-client

public String getResponseBodyExcerpt(int maxLength) throws IOException {
  return response.getResponseBodyExcerpt(maxLength);
}

代码示例来源:origin: io.gatling/async-http-client

public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException {
  return response.getResponseBodyExcerpt(maxLength, charset);
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-client

public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException {
  return response.getResponseBodyExcerpt(maxLength, charset);
}

代码示例来源:origin: io.gatling/async-http-client

public String getResponseBodyExcerpt(int maxLength) throws IOException {
  return response.getResponseBodyExcerpt(maxLength);
}

代码示例来源:origin: javaee/grizzly-ahc

public String getResponseBodyExcerpt(int maxLength) throws IOException {
  return response.getResponseBodyExcerpt(maxLength);
}

代码示例来源:origin: javaee/grizzly-ahc

public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException {
  return response.getResponseBodyExcerpt(maxLength, charset);
}

代码示例来源:origin: com.hubspot/SingularityService

@Override
public Response onCompleted(Response response) throws Exception {
 Optional<String> responseBody = Optional.absent();
 if (response.hasResponseBody()) {
  responseBody = Optional.of(response.getResponseBodyExcerpt(maxHealthcheckResponseBodyBytes));
 }
 saveResult(Optional.of(response.getStatusCode()), responseBody, Optional.<String> absent(), Optional.<Throwable>absent());
 return response;
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
  public Response onCompleted(Response response) throws Exception {
    try {
      String xContentType = response.getHeader("X-Content-Type");
      String boundary = xContentType.substring((xContentType.indexOf("boundary") + "boundary".length() + 1));
      String s = response.getResponseBodyExcerpt(boundary.length() + "--".length()).substring("--".length());
      assertEquals(boundary, s);
    } finally {
      l.countDown();
    }
    return response;
  }
}).get();

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider", "async" })
public void asyncResponseBodyTooLarge() throws Throwable {
  try (AsyncHttpClient client = getAsyncHttpClient(null)) {
    Response response = client.preparePost(getTargetUrl()).setBody("0123456789").execute(new AsyncCompletionHandlerAdapter() {
      @Override
      public void onThrowable(Throwable t) {
        Assert.fail("Unexpected exception", t);
      }
    }).get();
    Assert.assertNotNull(response.getResponseBodyExcerpt(Integer.MAX_VALUE));
  }
}

相关文章