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

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

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

HttpResponse.body介绍

暂无

代码示例

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

/**
 * Unzips GZip-ed body content, removes the content-encoding header
 * and sets the new content-length value.
 */
public HttpResponse unzip() {
  String contentEncoding = contentEncoding();
  if (contentEncoding != null && contentEncoding().equals("gzip")) {
    if (body != null) {
      headerRemove(HEADER_CONTENT_ENCODING);
      try {
        ByteArrayInputStream in = new ByteArrayInputStream(body.getBytes(StringPool.ISO_8859_1));
        GZIPInputStream gzipInputStream = new GZIPInputStream(in);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        StreamUtil.copy(gzipInputStream, out);
        body(out.toString(StringPool.ISO_8859_1));
      } catch (IOException ioex) {
        throw new HttpException(ioex);
      }
    }
  }
  return this;
}

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

assertEquals("text/html;charset=UTF-8", response.contentType());
assertEquals(utf8String, response.bodyText());
assertEquals(new String(utf8Bytes, StringPool.ISO_8859_1), response.body());

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

String rawBody = response.body();
String textBody = response.bodyText();

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

if (response.body() != null) {
  response.headerRemove("Transfer-Encoding");
  response.contentLength(response.body().length());

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

@Test
void testDirect() {
  HttpResponse response = HttpRequest.get("http://localhost:1080/get_books").send();
  assertEquals(200, response.statusCode());
  assertTrue(response.body().contains("Tatum"));
  proxy.verify(request().withPath("/get_books"), exactly(0));
}

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

@Test
@Disabled
void testHttpProxy() {
  SocketHttpConnectionProvider s = new SocketHttpConnectionProvider();
  s.useProxy(ProxyInfo.httpProxy("localhost", 1090, null, null));
  HttpResponse response = HttpRequest.get("http://localhost:1080/get_books")
    .withConnectionProvider(s)
    .send();
  assertEquals(200, response.statusCode());
  assertTrue(response.body().contains("Tatum"));
}

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

@Test
void testDirectHttps() {
  HttpResponse response = HttpRequest.get("https://localhost:1080/get_books").trustAllCerts(true).send();
  assertEquals(200, response.statusCode());
  assertTrue(response.body().contains("Tatum"));
  proxy.verify(request().withPath("/get_books"), exactly(0));
}

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

@Test
void testEcho() throws IOException {
  EchoTestServer echoTestServer = new EchoTestServer();
  HttpResponse response = HttpRequest.get("http://localhost:8081/hello?id=12").send();
  assertEquals(200, response.statusCode());
  assertEquals("OK", response.statusPhrase());
  assertEquals("GET", echoTestServer.method);
  assertEquals("/hello", echoTestServer.uri);
  assertEquals(1, echoTestServer.params.size());
  assertEquals("12", echoTestServer.params.get("id"));
  assertEquals("GET /hello", response.body());
  echoTestServer.stop();
}

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

@Test
void testUploadWithUploadable() throws IOException {
  EchoTestServer echoTestServer = new EchoTestServer();
  HttpResponse response = HttpRequest
      .post("http://localhost:8081/hello")
      .multipart(true)
      .form("id", "12")
      .form("file", new ByteArrayUploadable(
        "upload тест".getBytes(StringPool.UTF_8), "d ст", MimeTypes.MIME_TEXT_PLAIN))
      .send();
  assertEquals(200, response.statusCode());
  assertEquals("OK", response.statusPhrase());
  assertEquals("POST", echoTestServer.method);
  assertEquals("12", echoTestServer.params.get("id"));
  File uploadedFile = new File(echoTestServer.files.get("file").toString());
  assertNotNull(uploadedFile);
  assertEquals("upload тест", FileUtil.readString(uploadedFile));
  assertEquals("POST /hello", response.body());
  echoTestServer.stop();
}

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

@Test
void testBrowserRedirect() {
  HttpBrowser httpBrowser = new HttpBrowser();
  httpBrowser.sendRequest(HttpRequest.get("localhost:8173/redirect"));
  HttpResponse httpResponse = httpBrowser.getHttpResponse();
  assertEquals(200, httpResponse.statusCode());
  assertEquals("target!", httpResponse.body());
}

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

@Test
void testUpload() throws IOException {
  EchoTestServer echoTestServer = new EchoTestServer();
  File file = FileUtil.createTempFile();
  file.deleteOnExit();
  FileUtil.writeString(file, "upload тест");
  assertEquals("upload тест", FileUtil.readString(file));
  HttpResponse response = HttpRequest
      .post("http://localhost:8081/hello")
      .form("id", "12")
      .form("file", file)
      .send();
  assertEquals(200, response.statusCode());
  assertEquals("OK", response.statusPhrase());
  assertEquals("POST", echoTestServer.method);
  assertEquals("12", echoTestServer.params.get("id"));
  File uploadedFile = new File(echoTestServer.files.get("file").toString());
  assertNotNull(uploadedFile);
  assertEquals("upload тест", FileUtil.readString(uploadedFile));
  assertEquals("POST /hello", response.body());
  echoTestServer.stop();
  file.delete();
}

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

@Test
void testSocks5Proxy() {
  SocketHttpConnectionProvider s = new SocketHttpConnectionProvider();
  s.useProxy(ProxyInfo.socks5Proxy("localhost", 1090, null, null));
  HttpResponse response = HttpRequest.get("http://localhost:1080/get_books")
    .withConnectionProvider(s)
    .send();
  assertEquals(200, response.statusCode());
  assertTrue(response.body().contains("Tatum"));
  proxy.verify(request().withPath("/get_books"), exactly(1));
}

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

@Test
void testRedirect() {
  HttpRequest httpRequest = HttpRequest.get("localhost:8173/redirect");
  HttpResponse httpResponse = httpRequest.send();
  assertEquals(302, httpResponse.statusCode);
  HttpBrowser httpBrowser = new HttpBrowser();
  httpBrowser.sendRequest(
      HttpRequest.get("localhost:8173/redirect"));
  httpResponse = httpBrowser.getHttpResponse();
  assertNotNull(httpResponse);
  assertEquals("target!", httpResponse.body());
}

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

@Test
void testSocks5ProxyWithHttps() {
  SocketHttpConnectionProvider s = new SocketHttpConnectionProvider();
  s.useProxy(ProxyInfo.socks5Proxy("localhost", 1090, null, null));
  HttpResponse response = HttpRequest.get("https://localhost:1080/get_books")
    .withConnectionProvider(s)
    .trustAllCerts(true)
    .send();
  assertEquals(200, response.statusCode());
  assertTrue(response.body().contains("Tatum"));
  proxy.verify(request().withPath("/get_books"), exactly(1));
}

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

@Test
void testBrowser() {
  HttpBrowser httpBrowser = new HttpBrowser();
  httpBrowser.sendRequest(
    HttpRequest
      .get("localhost:8173/echo?id=17")
      .cookies(new Cookie("waffle", "jam"))
      .bodyText("hello"));
  HttpResponse httpResponse = httpBrowser.getHttpResponse();
  assertNotNull(httpResponse);
  assertEquals("hello", httpResponse.body());
  Cookie[] cookies = httpResponse.cookies();
  assertEquals(1, cookies.length);
  assertEquals("waffle", cookies[0].getName());
  assertEquals("jam!", cookies[0].getValue());
}

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

/**
 * Unzips GZip-ed body content, removes the content-encoding header
 * and sets the new content-length value.
 */
public HttpResponse unzip() {
  String contentEncoding = contentEncoding();
  if (contentEncoding != null && contentEncoding().equals("gzip")) {
    if (body != null) {
      headerRemove(HEADER_CONTENT_ENCODING);
      try {
        ByteArrayInputStream in = new ByteArrayInputStream(body.getBytes(StringPool.ISO_8859_1));
        GZIPInputStream gzipInputStream = new GZIPInputStream(in);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        StreamUtil.copy(gzipInputStream, out);
        body(out.toString(StringPool.ISO_8859_1));
      } catch (IOException ioex) {
        throw new HttpException(ioex);
      }
    }
  }
  return this;
}

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

if (response.body() != null) {
  response.headerRemove("Transfer-Encoding");
  response.contentLength(response.body().length());

代码示例来源:origin: com.haoxuer.discover/discover-pay

HttpResponse response = httpRequest.send();
if (response.statusCode() == 200) {
 String body = response.body();
 body = StringUtil.convertCharset(body, "ISO-8859-1", "UTF-8");
 System.out.println(body);

代码示例来源:origin: com.liferay.launchpad/api-transport-jodd

clientResponse.body(response.body());

相关文章