jodd.http.HttpRequest.body()方法的使用及代码示例

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

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

HttpRequest.body介绍

暂无

代码示例

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

@Test
void testBigRequest() throws IOException {
  InputStream inputStream = ClassLoaderUtil.getResourceAsStream("/jodd/http/answer.json");
  FastCharArrayWriter writter = StreamUtil.copy(inputStream);
  String body = writter.toString();
  HttpRequest httpRequest = HttpRequest.get("").body(body);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  httpRequest.sendTo(outputStream);
  String receivedBody = outputStream.toString();
  int ndx = receivedBody.indexOf("{");
  receivedBody = receivedBody.substring(ndx);
  assertEquals(body, receivedBody);
}

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

String rawBody = request.body();
assertEquals(utf8StringRealLen, rawBody.length());
assertArrayEquals(utf8Bytes, request.bodyBytes());

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

@Test
void testNegativeContentLength() {
  HttpRequest request = HttpRequest.get("http://jodd.org/?id=173");
  request.contentLength(-123);
  byte[] bytes = request.toByteArray();
  try {
    HttpRequest request2 = HttpRequest.readFrom(new ByteArrayInputStream(bytes));
    assertEquals("", request2.body());
  } catch (Exception ex) {
    fail(ex.toString());
  }
  // the same test but with missing content length
  request = HttpRequest.get("http://jodd.org/?id=173");
  bytes = request.toByteArray();
  try {
    HttpRequest request2 = HttpRequest.readFrom(new ByteArrayInputStream(bytes));
    assertEquals("", request2.body());
  } catch (Exception ex) {
    fail(ex.toString());
  }
}

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

/**
 * http post请求(body带参)
 * @param url 请求地址
 * @param param 请求参数
 * @return
 */
public static String body(String url, Map<String,Object> param,Map<String,String> headers){
  String result=null;
  try {
    HttpRequest httpRequest = HttpRequest.post(url).contentTypeJson();
    if(null!=param){
      httpRequest.body(JSON.toJSONString(param));
    }else{
      httpRequest.body("{}");
    }
    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.haoxuer.discover/discover-pay

HttpRequest httpRequest = HttpRequest.post("https://api.mch.weixin.qq.com/pay/unifiedorder");
String x = xstream.toXML(data);
httpRequest.body(StringUtil.convertCharset(x, "UTF-8", "ISO-8859-1"));
HttpResponse response = httpRequest.send();
if (response.statusCode() == 200) {

代码示例来源: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 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: com.liferay.launchpad/api-transport-jodd

httpRequest.body(body);

相关文章