jodd.http.HttpResponse.header()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(107)

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

HttpResponse.header介绍

暂无

代码示例

代码示例来源:origin: oblac/jodd

/**
 * Parses 'location' header to return the next location or returns {@code null} if location not specified.
 * Specification (<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30">rfc2616</a>)
 * says that only absolute path must be provided, however, this does not
 * happens in the real world. There a <a href="https://tools.ietf.org/html/rfc7231#section-7.1.2">proposal</a>
 * that allows server name etc to be omitted.
 */
public String location() {
  String location = header("location");
  if (location == null) {
    return null;
  }
  if (location.startsWith(StringPool.SLASH)) {
    location = getHttpRequest().hostUrl() + location;
  }
  return location;
}

代码示例来源:origin: oblac/jodd

@Test
void testRawResponse5() throws IOException {
  URL data = RawTest.class.getResource("5-response.txt");
  String fileContent = FileUtil.readString(data.getFile());
  fileContent = StringUtil.replace(fileContent, "\n", "\r\n");
  fileContent = StringUtil.replace(fileContent, "\r\r\n", "\r\n");
  HttpResponse response = HttpResponse.readFrom(new ByteArrayInputStream(fileContent.getBytes("UTF-8")));
  String body = response.bodyText();
  assertEquals(
      "Wikipedia in\n" +
      "\n" +
      "chunks.", body.replace("\r\n", "\n"));
  assertEquals("TheData", response.header("SomeAfterHeader"));
}

代码示例来源:origin: oblac/jodd

@Test
void testRawResponse6() throws IOException {
  URL data = RawTest.class.getResource("6-response.txt");
  String fileContent = FileUtil.readString(data.getFile());
  fileContent = StringUtil.replace(fileContent, "\n", "\r\n");
  fileContent = StringUtil.replace(fileContent, "\r\r\n", "\r\n");
  HttpResponse response = HttpResponse.readFrom(new ByteArrayInputStream(fileContent.getBytes("UTF-8")));
  assertEquals(200, response.statusCode());
  assertEquals("", response.statusPhrase);
  String body = response.bodyText();
  assertEquals(
      "Wikipedia in\n" +
      "\n" +
      "chunks.", body.replace("\r\n", "\n"));
  assertEquals("TheData", response.header("SomeAfterHeader"));
}

代码示例来源:origin: oblac/jodd

assertEquals("102", headers.get("content-length"));
assertEquals("no-cache", response.header("Pragma"));
assertEquals("text/html;charset=UTF-8" , response.contentType());
assertEquals("text/html" , response.mediaType());

代码示例来源:origin: binarywang/WxJava

private String getFileName(HttpResponse response) throws WxErrorException {
 String content = response.header("Content-disposition");
 return this.extractFileNameFromContentString(content);
}

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

private String getFileName(HttpResponse response) throws WxErrorException {
 String content = response.header("Content-disposition");
 return this.extractFileNameFromContentString(content);
}

代码示例来源:origin: org.jodd/jodd-http

/**
 * Parses 'location' header to return the next location or returns {@code null} if location not specified.
 * Specification (<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30">rfc2616</a>)
 * says that only absolute path must be provided, however, this does not
 * happens in the real world. There a <a href="https://tools.ietf.org/html/rfc7231#section-7.1.2">proposal</a>
 * that allows server name etc to be omitted.
 */
public String location() {
  String location = header("location");
  if (location == null) {
    return null;
  }
  if (location.startsWith(StringPool.SLASH)) {
    location = getHttpRequest().hostUrl() + location;
  }
  return location;
}

代码示例来源:origin: binarywang/WxJava

@Override
 public File execute(String uri, WxMaQrcodeParam qrcodeParam) throws WxErrorException, IOException {
  if (qrcodeParam != null && StringUtils.isNotBlank(qrcodeParam.getPagePath())) {
   if (uri.indexOf('?') == -1) {
    uri += '?';
   }
   uri += uri.endsWith("?")
    ? "path=" + URLEncoder.encode(qrcodeParam.getRequestPath(), "UTF-8")
    : "&path=" + URLEncoder.encode(qrcodeParam.getRequestPath(), "UTF-8");
  }

  HttpRequest request = HttpRequest.get(uri);
  if (requestHttp.getRequestHttpProxy() != null) {
   requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
  }
  request.withConnectionProvider(requestHttp.getRequestHttpClient());

  HttpResponse response = request.send();
  response.charset(StringPool.UTF_8);
  String contentTypeHeader = response.header("Content-Type");
  if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) {
   String responseContent = response.bodyText();
   throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
  }
  try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
   return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
  }
 }
}

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

@Override
 public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException, IOException {
  if (ticket != null) {
   if (uri.indexOf('?') == -1) {
    uri += '?';
   }
   uri += uri.endsWith("?")
    ? "ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8")
    : "&ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8");
  }

  HttpRequest request = HttpRequest.get(uri);
  if (requestHttp.getRequestHttpProxy() != null) {
   requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
  }
  request.withConnectionProvider(requestHttp.getRequestHttpClient());

  HttpResponse response = request.send();
  response.charset(StringPool.UTF_8);
  String contentTypeHeader = response.header("Content-Type");
  if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) {
   String responseContent = response.bodyText();
   throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
  }
  try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
   return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
  }
 }
}

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

response.charset(StringPool.UTF_8);
String contentType = response.header("Content-Type");
if (contentType != null && contentType.startsWith("application/json")) {

代码示例来源:origin: binarywang/WxJava

@Override
 public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException, IOException {
  if (ticket != null) {
   if (uri.indexOf('?') == -1) {
    uri += '?';
   }
   uri += uri.endsWith("?")
    ? "ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8")
    : "&ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8");
  }

  HttpRequest request = HttpRequest.get(uri);
  if (requestHttp.getRequestHttpProxy() != null) {
   requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
  }
  request.withConnectionProvider(requestHttp.getRequestHttpClient());

  HttpResponse response = request.send();
  response.charset(StringPool.UTF_8);
  String contentTypeHeader = response.header("Content-Type");
  if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) {
   String responseContent = response.bodyText();
   throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
  }
  try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
   return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
  }
 }
}

代码示例来源:origin: binarywang/WxJava

response.charset(StringPool.UTF_8);
String contentType = response.header("Content-Type");
if (contentType != null && contentType.startsWith("application/json")) {

相关文章