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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Python学习笔记(一)PyCharm社区版安装教程

    Python学习笔记(一)PyCharm社区版安装教程因为工作的原因,这两个月开始学习Python。准备把学习的东西记录一下。因为是自己的电脑,有python3.8,但是没有安装编译器,所以从PyCharm安装开始。(安装python会自带IDLE编辑器,自己学习的时候用着挺合适的,但是要用于工作或者其他大一些的项目,还是安装PyCharm比较合适)接下来开始安装教程。1、首先通过官网下载PyCharm社区版的安装包。下图中可以看到,PyCharm分为专业版(Professional)和社区版(Community),推荐使用社区版,基本能满足.

    2022年8月29日
    3
  • jboss 配置文件_黑果小兵安装教程

    jboss 配置文件_黑果小兵安装教程一、Jboss下载:  1、点击 http://jbossas.jboss.org/downloads/找到合适的版本下载;  我这里是用的Jboss-as-7.1.1.Final版本,算是比较新的一个版本。    二、Jboss安装:  1、首先将下好的Jboss解压到自己想要存放的位置;  2、配置环境变量(非必要步骤),建议还是将环境变量配好,便于dos中命令操作;   …

    2022年9月27日
    3
  • MySQL日期格式化

    MySQL日期格式化示例date_format(now(),’%Y-%m-%d%H:%i:%S’)点位符详解%Y:年,4位%y:年,2位%M:月名%m:月,数值(00-12)%D:带有英文前缀的月中的天%d:月的天,数值(00-31)%e:月的天,数值(0-31)%H:小时(00-23)%h:小时(01-12)%I:小时(01-12)%i:分钟,数值(00-59)%S:秒(00…

    2022年6月3日
    42
  • Go学习——密码学

    Go学习——密码学

    2021年8月30日
    365
  • JetBrains CLion 2021 激活码【中文破解版】

    (JetBrains CLion 2021 激活码)JetBrains旗下有多款编译器工具(如:IntelliJ、WebStorm、PyCharm等)在各编程领域几乎都占据了垄断地位。建立在开源IntelliJ平台之上,过去15年以来,JetBrains一直在不断发展和完善这个平台。这个平台可以针对您的开发工作流进行微调并且能够提供…

    2022年3月28日
    44
  • 分布式+JVM+多线程+spring+微服务+面试(文末PDF免费获取)

    分布式+JVM+多线程+spring+微服务+面试(文末PDF免费获取)

    2020年11月13日
    178

发表回复

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

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