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


相关推荐

  • redis info命令详解

    redis info命令详解

    2021年9月14日
    46
  • ORA-12514 解决方法

    ORA-12514 解决方法场景:修改oracle系统参数之后,数据库重启,客户端报ORA-12514错误,其实这只是表象,实际并非Listener的问题。SELECT*FROMV$RESOURCE_LIMIT根据

    2022年7月1日
    24
  • linux详解sudoers

    linux详解sudoers文章目录sudo使用sudo命令执行过程赋予用户sudo操作的权限/etc/sudoers内容详解编辑/etc/sudoers命令作用域通配符以及取消命令输入密码时有反馈修改sudo会话时间实践sudoers文件详解sudo使用Linux是多用户多任务的操作系统,共享该系统的用户往往不只一个。出于安全性考虑,有必要通过useradd创建一些非root用户,只让它们拥有不完全的权限;如有…

    2022年6月20日
    37
  • java缓存技术的介绍

    java缓存技术的介绍一、什么是缓存1、Cache是高速缓冲存储器一种特殊的存储器子系统,其中复制了频繁使用的数据以利于快速访问2、凡是位于速度相差较大的两种硬件/软件之间的,用于协调两者数据传输速度差异的结构,均可称之为Cache二、缓存的分类1、基于web应用的系统架构图2、在系统架构的不同层级之间,为了加快访问速度,都可以存在缓存操作系统磁盘缓存->减少磁盘机械操作

    2022年10月5日
    0
  • 手动清除memcached缓存方法[通俗易懂]

    手动清除memcached缓存方法

    2022年2月8日
    44
  • 匹配电子邮箱的正则表达式_怎样设置电子邮箱

    匹配电子邮箱的正则表达式_怎样设置电子邮箱电子邮件格式  电子邮件地址的格式是域内部分@域,其中域内部分最长为64个字符,而域名最长可达255个字符。例如:name@domainname可以使用任意ASCII字符:大小写英文字母a-z,A-Z数字0-9name部分只允许输入‘-’、’_’、’.’。原则上字符  !#$%&’*±/=?^`{|}~  甚至空格都可以输入,但是有些邮件服务器会拒绝包含有特殊字符的邮件地址一般来说只允许输入‘-’、’_’、’.’这三个特殊符号字符‘.’不能

    2022年9月23日
    0

发表回复

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

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