org.apache.http.client.methods.CloseableHttpResponse.getHeaders()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(199)

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

CloseableHttpResponse.getHeaders介绍

暂无

代码示例

代码示例来源:origin: chanjarster/weixin-java-tools

protected String getFileName(CloseableHttpResponse response) {
 Header[] contentDispositionHeader = response.getHeaders("Content-disposition");
 Pattern p = Pattern.compile(".*filename=\"(.*)\"");
 Matcher m = p.matcher(contentDispositionHeader[0].getValue());
 m.matches();
 String fileName = m.group(1);
 return fileName;
}

代码示例来源:origin: chanjarster/weixin-java-tools

Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0) {

代码示例来源:origin: chanjarster/weixin-java-tools

Header[] contentTypeHeader = response.getHeaders("Content-Type");
if (contentTypeHeader != null && contentTypeHeader.length > 0) {

代码示例来源:origin: testcontainers/testcontainers-java

@Test
  public void simpleDslTest() throws IOException {
    String address = String.format("http://%s:%s", dslContainer.getContainerIpAddress(), dslContainer.getMappedPort(80));

    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    HttpGet get = new HttpGet(address);

    try (CloseableHttpResponse response = httpClient.execute(get)) {
      assertEquals("A container built from a dockerfile can run nginx as expected, and returns a good status code",
              200,
              response.getStatusLine().getStatusCode());
      assertTrue("A container built from a dockerfile can run nginx as expected, and returns an expected Server header",
              response.getHeaders("Server")[0].getValue().contains("nginx"));
    }
  }
}

代码示例来源:origin: sd4324530/fastweixin

private void downloadVideo(DownloadMaterialResponse response){
  String url = response.getDownUrl();
  LOG.debug("Download url: " + url);
  RequestConfig config = RequestConfig.custom().setConnectionRequestTimeout(NetWorkCenter.CONNECT_TIMEOUT).setConnectTimeout(NetWorkCenter.CONNECT_TIMEOUT).setSocketTimeout(NetWorkCenter.CONNECT_TIMEOUT).build();
  CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
  HttpGet get = new HttpGet(url);
  try {
    CloseableHttpResponse r = client.execute(get);
    if (HttpStatus.SC_OK == r.getStatusLine().getStatusCode()) {
      InputStream inputStream = r.getEntity().getContent();
      Header[] headers = r.getHeaders("Content-disposition");
      Header length = r.getHeaders("Content-Length")[0];
      response.setContent(inputStream, Integer.valueOf(length.getValue()));
      response.setFileName(headers[0].getElements()[0].getParameterByName("filename").getValue());
    }
  } catch (IOException e){
    LOG.error("IO异常处理", e);
  } catch (Exception e) {
    LOG.error("其他异常", e);
  }
}

代码示例来源:origin: borball/weixin-sdk

private byte[] httpGetBinary(String url) {
  HttpGet httpGet = new HttpGet(url);
  try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
    StatusLine statusLine = response.getStatusLine();
    HttpEntity entity = response.getEntity();
    if (statusLine.getStatusCode() >= 300) {
      EntityUtils.consume(entity);
      throw new WxRuntimeException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
    }
    Header[] contentTypeHeader = response.getHeaders("Content-Type");
    if (contentTypeHeader != null && contentTypeHeader.length > 0) {
      if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
        String responseContent = entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8);
        WxError wxError = WxError.fromJson(responseContent);
        if (wxError.getErrorCode() != 0) {
          throw new WxRuntimeException(wxError);
        }
      }
    }
    InputStream inputStream = response.getEntity().getContent();
    return IOUtils.toByteArray(inputStream);
  } catch (IOException ex) {
    logger.error("http get: {} failed.", url, ex);
    throw new WxRuntimeException(999, ex.getMessage());
  }
}

代码示例来源:origin: sd4324530/fastweixin

if(HttpStatus.SC_OK == r.getStatusLine().getStatusCode()){
  InputStream inputStream = r.getEntity().getContent();
  Header[] headers = r.getHeaders("Content-disposition");
  if (null != headers && 0 != headers.length) {
    Header length = r.getHeaders("Content-Length")[0];
    response.setContent(inputStream, Integer.valueOf(length.getValue()));
    response.setFileName(headers[0].getElements()[0].getParameterByName("filename").getValue());

代码示例来源:origin: borball/weixin-sdk

throw new WxRuntimeException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
} else {
  Header[] dispositionHeaders = response.getHeaders("Content-disposition");
  if (dispositionHeaders != null && dispositionHeaders.length > 0) {
    String fileName = extractFileName(dispositionHeaders[0].getValue());

代码示例来源:origin: sd4324530/fastweixin

if (HttpStatus.SC_OK == r.getStatusLine().getStatusCode()) {
  InputStream inputStream = r.getEntity().getContent();
  Header[] headers = r.getHeaders("Content-disposition");
  if (null != headers && 0 != headers.length) {
    Header length = r.getHeaders("Content-Length")[0];
    response.setContent(inputStream, Integer.valueOf(length.getValue()));
    response.setFileName(headers[0].getElements()[0].getParameterByName("filename").getValue());

代码示例来源:origin: sd4324530/fastweixin

Header length = httpResponse.getHeaders("Content-Length")[0];
InputStream inputStream = httpResponse.getEntity().getContent();
response.setContent(inputStream, Integer.valueOf(length.getValue()));

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.clients

@Override
public Header[] getHeaders(String name) {
  return httpResponse.getHeaders(name);
}

代码示例来源:origin: opensourceBIM/BIMserver

throw new UserException("Remote service responded with a 401 Unauthorized");
} else if (response.getStatusLine().getStatusCode() == 200) {
  Header[] headers = response.getHeaders("Content-Disposition");
  String filename = "unknown";
  if (headers.length > 0) {
    file.setFilename(filename);
    file.setSize(responseBytes.length);
    file.setMime(response.getHeaders("Content-Type")[0].getValue());
    Long fileId = uploadFile(file);

代码示例来源:origin: com.machinepublishers/jbrowserdriver

/**
 * {@inheritDoc}
 */
@Override
public int getHeaderFieldInt(String name, int defaultValue) {
 if (response.get() != null) {
  Header[] headers = response.get().getHeaders(name);
  if (headers != null && headers.length > 0) {
   return Integer.parseInt(headers[headers.length - 1].getValue());
  }
 }
 return defaultValue;
}

代码示例来源:origin: com.centit.support/centit-utils

protected static String extraFileName(CloseableHttpResponse response) {
  Header[] contentDispositionHeader = response
      .getHeaders("Content-disposition");
  Matcher m = Pattern.compile(".*filename=\"(.*)\"").matcher(contentDispositionHeader[0].getValue());
  if(m.matches()) {
    return m.group(1);
  }
  return null;
}

代码示例来源:origin: me.chanjar/weixin-java-common

protected String getFileName(CloseableHttpResponse response) {
 Header[] contentDispositionHeader = response.getHeaders("Content-disposition");
 Pattern p = Pattern.compile(".*filename=\"(.*)\"");
 Matcher m = p.matcher(contentDispositionHeader[0].getValue());
 m.matches();
 String fileName = m.group(1);
 return fileName;
}

代码示例来源:origin: osmlab/atlas

public Header[] getHeader(final String headerKey)
{
  // make sure that a connection attempt has been made
  onRead();
  return this.response.getHeaders(headerKey);
}

代码示例来源:origin: oracle/weblogic-monitoring-exporter

private String extractSessionSetCookieHeader(CloseableHttpResponse response) {
  for (Header header : response.getHeaders("Set-Cookie")) {
    String sessionCookie = ExporterSession.getSessionCookie(header.getValue());
    if (sessionCookie != null) return header.getValue();
  }
  return null;
}

代码示例来源:origin: neo4j/neo4j-ogm

private String newTransactionUrl(Transaction.Type type) {
  String url = transactionEndpoint(configuration.getURI());
  LOGGER.debug("Thread: {}, POST {}", Thread.currentThread().getId(), url);
  HttpPost request = new HttpPost(url);
  request.setHeader("X-WRITE", type == Transaction.Type.READ_ONLY ? "0" : "1");
  try (CloseableHttpResponse response = executeHttpRequest(request)) {
    Header location = response.getHeaders("Location")[0];
    return location.getValue();
  } catch (IOException ioe) {
    throw new HttpRequestException(request, ioe);
  }
}

代码示例来源:origin: org.neo4j/neo4j-ogm-drivers

private String newTransactionUrl() {
  String url = transactionEndpoint(driverConfig.getURI());
  logger.debug("POST {}", url);
  CloseableHttpResponse response = executeHttpRequest(new HttpPost(url));
  Header location = response.getHeaders("Location")[0];
  try {
    response.close();
    return location.getValue();
  } catch (IOException e) {
    throw new ResultProcessingException("Failed to execute request: ", e);
  }
}

代码示例来源:origin: com.github.binarywang/weixin-java-common

private String getFileName(CloseableHttpResponse response) throws WxErrorException {
 Header[] contentDispositionHeader = response.getHeaders("Content-disposition");
 if (contentDispositionHeader == null || contentDispositionHeader.length == 0) {
  throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").errorCode(99999).build());
 }
 return this.extractFileNameFromContentString(contentDispositionHeader[0].getValue());
}

相关文章