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

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

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

HttpResponse.bodyBytes介绍

暂无

代码示例

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

@Override
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
 try {
  HttpRequest request = this.buildHttpRequest(url, requestStr, useKey);
  byte[] responseBytes = request.send().bodyBytes();
  final String responseString = Base64.encodeToString(responseBytes);
  this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseString);
  if (this.getConfig().isIfSaveApiData()) {
   wxApiData.set(new WxPayApiData(url, requestStr, responseString, null));
  }
  return responseBytes;
 } catch (Exception e) {
  this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage());
  wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
  throw new WxPayException(e.getMessage(), e);
 }
}

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

@Override
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
 try {
  HttpRequest request = this.buildHttpRequest(url, requestStr, useKey);
  byte[] responseBytes = request.send().bodyBytes();
  final String responseString = Base64.encodeToString(responseBytes);
  this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseString);
  if (this.getConfig().isIfSaveApiData()) {
   wxApiData.set(new WxPayApiData(url, requestStr, responseString, null));
  }
  return responseBytes;
 } catch (Exception e) {
  this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage());
  wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
  throw new WxPayException(e.getMessage(), e);
 }
}

代码示例来源: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: com.github.binarywang/weixin-java-mp

@Override
 public InputStream execute(String uri, String materialId) throws WxErrorException, IOException {
  HttpRequest request = HttpRequest.post(uri);
  if (requestHttp.getRequestHttpProxy() != null) {
   requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
  }
  request.withConnectionProvider(requestHttp.getRequestHttpClient());

  request.query("media_id", materialId);
  HttpResponse response = request.send();
  response.charset(StringPool.UTF_8);
  try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
   // 下载媒体文件出错
   byte[] responseContent = IOUtils.toByteArray(inputStream);
   String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
   if (responseContentString.length() < 100) {
    try {
     WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
     if (wxError.getErrorCode() != 0) {
      throw new WxErrorException(wxError);
     }
    } catch (com.google.gson.JsonSyntaxException ex) {
     return new ByteArrayInputStream(responseContent);
    }
   }
   return new ByteArrayInputStream(responseContent);
  }
 }
}

代码示例来源: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: binarywang/WxJava

@Override
 public InputStream execute(String uri, String materialId) throws WxErrorException, IOException {
  HttpRequest request = HttpRequest.post(uri);
  if (requestHttp.getRequestHttpProxy() != null) {
   requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
  }
  request.withConnectionProvider(requestHttp.getRequestHttpClient());

  request.query("media_id", materialId);
  HttpResponse response = request.send();
  response.charset(StringPool.UTF_8);
  try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
   // 下载媒体文件出错
   byte[] responseContent = IOUtils.toByteArray(inputStream);
   String responseContentString = new String(responseContent, StandardCharsets.UTF_8);
   if (responseContentString.length() < 100) {
    try {
     WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
     if (wxError.getErrorCode() != 0) {
      throw new WxErrorException(wxError);
     }
    } catch (com.google.gson.JsonSyntaxException ex) {
     return new ByteArrayInputStream(responseContent);
    }
   }
   return new ByteArrayInputStream(responseContent);
  }
 }
}

代码示例来源: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-common

try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
 return FileUtils.createTmpFile(inputStream,
  FilenameUtils.getBaseName(fileName),

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

try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
 return FileUtils.createTmpFile(inputStream,
  FilenameUtils.getBaseName(fileName),

相关文章