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

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

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

HttpResponse.bodyText介绍

暂无

代码示例

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

/**
 * Returns last response HTML page.
 */
public String getPage() {
  if (httpResponse == null) {
    return null;
  }
  return httpResponse.bodyText();
}

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

@Test
void testNoContentLength() throws IOException {
  URL data = RawTest.class.getResource("3-response.txt");
  byte[] fileContent = FileUtil.readBytes(data.getFile());
  HttpResponse httpResponse = HttpResponse.readFrom(new ByteArrayInputStream(fileContent));
  assertEquals("Body!", httpResponse.bodyText());
}

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

@Test
void testNoBody() throws IOException {
  /*HttpResponse httpResponse = HttpRequest.get("http://maps.googleapis.com/maps/api/geocode/json")
          .query("address", "14621")
          .query("sensor", "false")
          .send();
   */
  URL data = RawTest.class.getResource("2-response.txt");
  byte[] fileContent = FileUtil.readBytes(data.getFile());
  HttpResponse httpResponse = HttpResponse.readFrom(new ByteArrayInputStream(fileContent));
  try {
    httpResponse.bodyText();
  } catch (Exception ex) {
    fail(ex.toString());
  }
  assertEquals("", httpResponse.bodyText());
}

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

@Test
void testRawResponse4() throws IOException {
  URL data = RawTest.class.getResource("4-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"));
}

代码示例来源: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(utf8String, response.bodyText());
assertEquals(new String(utf8Bytes, StringPool.ISO_8859_1), response.body());

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

String textBody = response.bodyText();

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

/**
 * Returns last response HTML page.
 */
public String getPage() {
  if (httpResponse == null) {
    return null;
  }
  return httpResponse.bodyText();
}

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

private String getResponseString(HttpResponse response) throws WxPayException {
 try {
  this.log.debug("【微信服务器响应头信息】:\n{}", response.toString(false));
 } catch (NullPointerException e) {
  this.log.warn("HttpResponse.toString() 居然抛出空指针异常了", e);
 }
 String responseString = response.bodyText();
 if (StringUtils.isBlank(responseString)) {
  throw new WxPayException("响应信息为空");
 }
 if (StringUtils.isBlank(response.charset())) {
  responseString = new String(responseString.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
 }
 return responseString;
}

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

private String getResponseString(HttpResponse response) throws WxPayException {
 try {
  this.log.debug("【微信服务器响应头信息】:\n{}", response.toString(false));
 } catch (NullPointerException e) {
  this.log.warn("HttpResponse.toString() 居然抛出空指针异常了", e);
 }
 String responseString = response.bodyText();
 if (StringUtils.isBlank(responseString)) {
  throw new WxPayException("响应信息为空");
 }
 if (StringUtils.isBlank(response.charset())) {
  responseString = new String(responseString.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
 }
 return responseString;
}

代码示例来源:origin: com.gitee.morilys.jsmile/jsmile-kit

/**
 * http get请求
 * @param url 请求地址
 * @param param 请求参数
 * @return
 */
public static String post(String url, Map<String,Object> param,Map<String,String> headers){
  String result=null;
  try {
    HttpRequest httpRequest = HttpRequest.post(url);
    if(null!=param){
      httpRequest.form(param);
    }
    if(headers!=null&&!headers.isEmpty()){
      httpRequest.header(headers);
    }
    HttpResponse response = httpRequest.send().charset(HttpConstant.Charsets.DEFAULT_CHARSET);
    result = response.bodyText();
  }catch (Exception e){
    logger.error("HTTP请求地址【" + url + "】发生异常:" + ExceptionUtils.getRootCause(e));
  }
  return result;
}

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

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

  HttpRequest request = HttpRequest.post(uri)
   .withConnectionProvider(requestHttp.getRequestHttpClient())
   .body(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId)));
  HttpResponse response = request.send();
  response.charset(StringPool.UTF_8);

  String responseContent = response.bodyText();
  this.logger.debug("响应原始数据:{}", responseContent);
  WxError error = WxError.fromJson(responseContent, WxType.MP);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  } else {
   return WxMpGsonBuilder.create().fromJson(responseContent, WxMpMaterialNews.class);
  }
 }
}

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

@Override
 public Boolean 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);
  String responseContent = response.bodyText();
  WxError error = WxError.fromJson(responseContent, WxType.MP);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  } else {
   return true;
  }
 }
}

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

@Override
 public Boolean 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);
  String responseContent = response.bodyText();
  WxError error = WxError.fromJson(responseContent, WxType.MP);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  } else {
   return true;
  }
 }
}

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

@Override
 public WxMpMaterialVideoInfoResult 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);
  String responseContent = response.bodyText();
  WxError error = WxError.fromJson(responseContent, WxType.MP);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  } else {
   return WxMpMaterialVideoInfoResult.fromJson(responseContent);
  }
 }
}

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

@Override
 public WxMediaUploadResult execute(String uri, File file) throws WxErrorException, IOException {
  HttpRequest request = HttpRequest.post(uri);
  if (requestHttp.getRequestHttpProxy() != null) {
   requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
  }
  request.withConnectionProvider(requestHttp.getRequestHttpClient());
  request.form("media", file);
  HttpResponse response = request.send();
  response.charset(StringPool.UTF_8);

  String responseContent = response.bodyText();
  WxError error = WxError.fromJson(responseContent);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  }
  return WxMediaUploadResult.fromJson(responseContent);
 }
}

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

@Override
 public WxMediaUploadResult execute(String uri, File file) throws WxErrorException, IOException {
  HttpRequest request = HttpRequest.post(uri);
  if (requestHttp.getRequestHttpProxy() != null) {
   requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
  }
  request.withConnectionProvider(requestHttp.getRequestHttpClient());
  request.form("media", file);
  HttpResponse response = request.send();
  response.charset(StringPool.UTF_8);

  String responseContent = response.bodyText();
  WxError error = WxError.fromJson(responseContent);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  }
  return WxMediaUploadResult.fromJson(responseContent);
 }
}

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

@Override
 public WxMpMaterialVideoInfoResult 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);
  String responseContent = response.bodyText();
  WxError error = WxError.fromJson(responseContent, WxType.MP);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  } else {
   return WxMpMaterialVideoInfoResult.fromJson(responseContent);
  }
 }
}

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

@Override
 public WxMediaImgUploadResult execute(String uri, File data) throws WxErrorException, IOException {
  if (data == null) {
   throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build());
  }

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

  request.form("media", data);
  HttpResponse response = request.send();
  response.charset(StringPool.UTF_8);
  String responseContent = response.bodyText();
  WxError error = WxError.fromJson(responseContent, WxType.MP);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  }

  return WxMediaImgUploadResult.fromJson(responseContent);
 }
}

相关文章