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

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

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

HttpRequest.contentType介绍

[英]Specifies JSON content type.
[中]指定JSON内容类型。

代码示例

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

/**
 * Specifies JSON content type.
 */
public HttpRequest contentTypeJson() {
  return contentType(MimeTypes.MIME_APPLICATION_JSON);
}

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

@Test
void testContentTypeHeader() {
  HttpRequest req = HttpRequest.get("localhost/hello");
  assertNull(req.contentType());
  req.contentType("text/plain;charset=UTF-8");
  assertEquals("text/plain", req.mediaType());
  assertEquals("UTF-8", req.charset());
  assertEquals("text/plain;charset=UTF-8", req.contentType());
  req.mediaType("text/html");
  assertEquals("text/html;charset=UTF-8", req.contentType());
  req.mediaType(null);
  assertEquals("text/html;charset=UTF-8", req.contentType());
  req.charset("ASCII");
  assertEquals("text/html;charset=ASCII", req.contentType());
  req.charset(null);
  assertEquals("text/html", req.contentType());
  req.contentType("text/plain;charset=UTF-8;boundary=123");
  assertEquals("text/plain", req.mediaType());
  assertEquals("UTF-8", req.charset());
  assertEquals("text/plain;charset=UTF-8;boundary=123", req.contentType());
}

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

/**
 * Specifies JSON content type.
 */
public HttpRequest contentTypeJson() {
  return contentType(MimeTypes.MIME_APPLICATION_JSON);
}

相关文章