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

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

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

HttpRequest.path介绍

[英]Returns request path, without the query.
[中]返回请求路径,不带查询。

代码示例

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

path(destination);

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

public static HttpRequest readFrom(final InputStream in, final String encoding) {
  BufferedReader reader;
  try {
    reader = new BufferedReader(new InputStreamReader(in, encoding));
  } catch (UnsupportedEncodingException uneex) {
    return null;
  }
  final HttpRequest httpRequest = new HttpRequest();
  httpRequest.headers.clear();
  final String line;
  try {
    line = reader.readLine();
  } catch (IOException ioex) {
    throw new HttpException(ioex);
  }
  if (!StringUtil.isBlank(line)) {
    String[] s = StringUtil.splitc(line, ' ');
    httpRequest.method(s[0]);
    httpRequest.path(s[1]);
    httpRequest.httpVersion(s[2]);
    httpRequest.readHeaders(reader);
    httpRequest.readBody(reader);
  }
  return httpRequest;
}

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

HttpRequest httpRequest = new HttpRequest();
httpRequest.path("");
assertEquals("/", httpRequest.path());
httpRequest.path("jodd");
assertEquals("/jodd", httpRequest.path());
assertNotNull(httpRequest.query());
assertEquals(0, httpRequest.query().size());
assertEquals("/jodd", httpRequest.path());

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

assertEquals("jodd.org", httpRequest.host());
assertEquals(173, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
assertEquals("jodd.org", httpRequest.host());
assertEquals(173, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
assertEquals("jodd.org", httpRequest.host());
assertEquals(173, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
assertEquals("jodd.org", httpRequest.host());
assertEquals(80, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
assertEquals("localhost", httpRequest.host());
assertEquals(80, httpRequest.port());
assertEquals("/index.html", httpRequest.path());
assertEquals("true", httpRequest.query().get("light"));
assertEquals("jodd.org", httpRequest.host());
assertEquals(80, httpRequest.port());
assertEquals("/", httpRequest.path());

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

path(destination);

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

public static HttpRequest readFrom(final InputStream in, final String encoding) {
  BufferedReader reader;
  try {
    reader = new BufferedReader(new InputStreamReader(in, encoding));
  } catch (UnsupportedEncodingException uneex) {
    return null;
  }
  final HttpRequest httpRequest = new HttpRequest();
  httpRequest.headers.clear();
  final String line;
  try {
    line = reader.readLine();
  } catch (IOException ioex) {
    throw new HttpException(ioex);
  }
  if (!StringUtil.isBlank(line)) {
    String[] s = StringUtil.splitc(line, ' ');
    httpRequest.method(s[0]);
    httpRequest.path(s[1]);
    httpRequest.httpVersion(s[2]);
    httpRequest.readHeaders(reader);
    httpRequest.readBody(reader);
  }
  return httpRequest;
}

相关文章