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

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

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

HttpRequest.readFrom介绍

[英]Parses input stream and creates new HttpRequest object. Assumes input stream is in ISO_8859_1 encoding.
[中]解析输入流并创建新的HttpRequest对象。假设输入流采用ISO_8859_1编码。

代码示例

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

/**
 * Parses input stream and creates new <code>HttpRequest</code> object.
 * Assumes input stream is in ISO_8859_1 encoding.
 */
public static HttpRequest readFrom(final InputStream in) {
  return readFrom(in, StringPool.ISO_8859_1);
}

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

HttpRequest request = HttpRequest.readFrom(socketInput);

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

@Test
void testHttpRequestSlash() {
  HttpRequest request = HttpRequest.post("/");
  request.contentType("application/x-www-form-urlencoded");
  HttpRequest request1 = HttpRequest.readFrom(new ByteArrayInputStream(request.toByteArray()));
  assertEquals(request.toString(), request1.toString());
}

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

@Test
void testHttpRequestReRead() {
  HttpRequest request = HttpRequest.post("http://127.0.0.1:8086/test");
  request.form("a", null);
  request.form("b", "aaa");
  HttpRequest request1 = HttpRequest.readFrom(new ByteArrayInputStream(request.toByteArray()));
  assertEquals(request.toString(), request1.toString());
}

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

@Test
void testFileUpload() throws IOException {
  HttpRequest request = HttpRequest.get("http://jodd.org/?id=173");
  request.header("User-Agent", "Scaly").form("one", "funny");
  File tempFile = FileUtil.createTempFile();
  tempFile.deleteOnExit();
  FileUtil.writeString(tempFile, "qwerty");
  request.form("two", tempFile);
  byte[] bytes = request.toByteArray();
  // read
  HttpRequest request2 = HttpRequest.readFrom(new ByteArrayInputStream(bytes));
  HttpMultiMap<?> httpParams2 = request2.form();
  assertEquals(request.method(), request2.method());
  assertEquals(request.path(), request2.path());
  assertEquals(request.queryString(), request2.queryString());
  assertEquals(request.header("User-Agent"), request2.header("User-Agent"));
  assertEquals(request.header("Content-Type"), request2.header("content-type"));
  assertEquals(request.header("Content-Length"), request2.header("content-length"));
  HttpMultiMap<?> params1 = request.form();
  HttpMultiMap<?> params2 = request2.form();
  assertEquals(params1.size(), params2.size());
  assertEquals(params2.get("one"), params2.get("one"));
  FileUpload fu = (FileUpload) httpParams2.get("two");
  assertEquals(6, fu.getSize());
  String str = new String(fu.getFileContent());
  assertEquals("qwerty", str);
  tempFile.delete();
}

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

@Test
void testInOutForm() {
  HttpRequest request = HttpRequest.get("http://jodd.org/?id=173");
  request.header("User-Agent", "Scaly");
  request.form("one", "funny");
  byte[] bytes = request.toByteArray();
  // read
  HttpRequest request2 = HttpRequest.readFrom(new ByteArrayInputStream(bytes));
  assertEquals(request.method(), request2.method());
  assertEquals(request.path(), request2.path());
  assertEquals(request.queryString(), request2.queryString());
  assertEquals(request.header("User-Agent"), request2.header("User-Agent"));
  assertEquals(request.header("Content-Type"), request2.header("content-type"));
  assertEquals(request.header("Content-Length"), request2.header("content-length"));
  HttpMultiMap<?> params1 = request.form();
  HttpMultiMap<?> params2 = request2.form();
  assertEquals(params1.size(), params2.size());
  assertEquals(params2.get("one"), params2.get("one"));
}

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

/**
 * Parses input stream and creates new <code>HttpRequest</code> object.
 * Assumes input stream is in ISO_8859_1 encoding.
 */
public static HttpRequest readFrom(final InputStream in) {
  return readFrom(in, StringPool.ISO_8859_1);
}

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

HttpRequest request = HttpRequest.readFrom(socketInput);

相关文章