java mediatype属性_Java MediaType.MULTIPART_FORM_DATA属性代码示例[通俗易懂]

java mediatype属性_Java MediaType.MULTIPART_FORM_DATA属性代码示例[通俗易懂]/***Triestodeterminethecontent/mediatypeofthisHTTPrequestifftheHTTP”Content-Type”*headerwasnotexplicitlysetbytheuser,otherwisetheuserprovidedvalueisused.Ifthe*”Content-…

大家好,又见面了,我是你们的朋友全栈君。

/**

* Tries to determine the content/media type of this HTTP request iff the HTTP “Content-Type”

* header was not explicitly set by the user, otherwise the user provided value is used. If the

* “Content-Type” HTTP header value is null, then the content/media/payload of this HTTP request

* is inspected to determine the content type.

*

* The simplest evaluation sets the content type to “application/x-www-form-urlencoded” if this is

* a POST or PUT HTTP request, unless any request parameter value is determined to have multiple

* parts, the the content type will be “multipart/form-data”.

*

*

* @param defaultContentType the default content/media type to use when the content type cannot be

* determined from this HTTP request.

* @return a MediaType for the value of the HTTP Content-Type header as determined from this HTTP

* request.

* @see #getHeaders()

* @see org.springframework.http.HttpHeaders#getContentType()

* @see org.springframework.http.MediaType

*/

protected MediaType determineContentType(final MediaType defaultContentType) {

MediaType contentType = getHeaders().getContentType();

// if the content type HTTP header was not explicitly set, try to determine the media type from

// the content body

// of the HTTP request

if (contentType == null) {

if (isPost() || isPut()) {

OUT: for (final String name : getParameters().keySet()) {

for (final Object value : getParameters().get(name)) {

if (value != null && !(value instanceof String)) {

contentType = MediaType.MULTIPART_FORM_DATA;

break OUT;

}

}

}

// since this is a POST/PUT HTTP request, default the content/media type to

// “application/x-www-form-urlencoded”

contentType = ObjectUtils.defaultIfNull(contentType, MediaType.APPLICATION_FORM_URLENCODED);

} else {

// NOTE the “Content-Type” HTTP header is not applicable to GET/DELETE and other methods of

// HTTP requests

// since there is typically no content (media/payload/request body/etc) to send. Any request

// parameters

// are encoded in the URL as query parameters.

}

}

return ObjectUtils.defaultIfNull(contentType, defaultContentType);

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/141436.html原文链接:https://javaforall.net

(0)
上一篇 2022年5月25日 下午10:00
下一篇 2022年5月25日 下午10:20


相关推荐

  • 百度的手机“龙虾”上线秒光,OpenClaw创始人邀共同开发

    百度的手机“龙虾”上线秒光,OpenClaw创始人邀共同开发

    2026年3月13日
    1
  • Jdbc系列六:ResultSetMetaData类

    Jdbc系列六:ResultSetMetaData类一 使用 JDBC 驱动程序处理元数据 Java 通过 JDBC 获得连接以后 得到一个 Connection 对象 可以从这个对象获得有关数据库管理系统的各种信息 包括数据库中的各个表 表中的各个列 数据类型 触发器 存储过程等各方面的信息 根据这些信息 JDBC 可以访问一个实现事先并不了解的数据库 获取这些信息的方法都是在 DatabaseMeta 类的对象上实现的 而 DataBaseMe

    2026年2月22日
    3
  • C++中int 转char

    C++中int 转charC 中 int 转 char inta 10 0 1 2 3 4 5 6 7 8 9 charb a 1 0 则 b 的值为字符 1

    2026年3月26日
    2
  • java 接口学习

    你应该知道接口是一种契约,它与实现方式无关但是类,即使是抽象类,你都能自定义成员变量,而成员变量往往就与实现方式有关。这一点的实际意义不大。但是有一点,类会暴露太多不必要,甚至不能暴露的东西,你

    2021年12月22日
    51
  • python函数闭包_python闭包的使用场景

    python函数闭包_python闭包的使用场景闭包首先了解一下:如果在一个函数的内部定义了另一个函数,外部的我们叫他外函数,内部的我们叫他内函数。在一个外函数中定义了一个内函数,内函数里运用了外函数的临时变量,并且外函数的返回值是内函数的引用

    2022年7月30日
    7
  • Java接口是什么意思_JAVA接口

    Java接口是什么意思_JAVA接口下看下接口定义@FunctionalInterfacepublicinterfaceSupplier<T>{/***Getsaresult.**@returnaresult*/Tget();}supplier英[səˈplaɪə(r)]美[səˈplaɪər]…

    2025年8月14日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号