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

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

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

HttpRequest.queryString介绍

[英]Generates query string. All values are URL encoded.
[中]生成查询字符串。所有值都是URL编码的。

代码示例

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

/**
 * @see #queryString(String, boolean)
 */
public HttpRequest queryString(final String queryString) {
  return queryString(queryString, true);
}

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

/**
 * Returns full URL path.
 * Simply concatenates {@link #protocol(String) protocol}, {@link #host(String) host},
 * {@link #port(int) port}, {@link #path(String) path} and {@link #queryString(String) query string}.
 */
public String url() {
  StringBuilder url = new StringBuilder();
  url.append(hostUrl());
  if (path != null) {
    url.append(path);
  }
  String queryString = queryString();
  if (StringUtil.isNotBlank(queryString)) {
    url.append('?');
    url.append(queryString);
  }
  return url.toString();
}

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

httpRequest.queryString("one=two");
assertEquals("/jodd", httpRequest.path());
httpRequest.queryString("one");
assertEquals("one", httpRequest.queryString());
params = httpRequest.query();
assertEquals(1, params.size());
assertNull(params.get("one"));
httpRequest.queryString("one=");
assertEquals("one=", httpRequest.queryString());
params = httpRequest.query();
assertEquals(1, params.size());
assertEquals("", params.get("one"));
httpRequest.queryString("one=aaa&two=bbb");
assertEquals("one=aaa&two=bbb", httpRequest.queryString());
params = httpRequest.query();
assertEquals(2, params.size());
httpRequest.queryString("one=&two=aaa");
assertEquals("one=&two=aaa", httpRequest.queryString());
params = httpRequest.query();
assertEquals(2, params.size());
httpRequest.queryString("one=Супер");
assertEquals("one=%D0%A1%D1%83%D0%BF%D0%B5%D1%80", httpRequest.queryString());
params = httpRequest.query();
assertEquals(1, params.size());

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

String queryString = queryString();

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

/**
 * @see #queryString(String, boolean)
 */
public HttpRequest queryString(final String queryString) {
  return queryString(queryString, true);
}

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

/**
 * Returns full URL path.
 * Simply concatenates {@link #protocol(String) protocol}, {@link #host(String) host},
 * {@link #port(int) port}, {@link #path(String) path} and {@link #queryString(String) query string}.
 */
public String url() {
  StringBuilder url = new StringBuilder();
  url.append(hostUrl());
  if (path != null) {
    url.append(path);
  }
  String queryString = queryString();
  if (StringUtil.isNotBlank(queryString)) {
    url.append('?');
    url.append(queryString);
  }
  return url.toString();
}

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

String queryString = queryString();

相关文章