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


相关推荐

  • springBoot+mybatis报错Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required

    springBoot+mybatis报错Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required报错为:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IllegalArgumentException:Property’sqlSessionFactory’or’sqlSessionTemplate’arerequired日志很长,报错在末尾2018-07-1213:56:41.760 I…

    2022年5月6日
    192
  • linux 下JDK卸载与安装

    linux 下JDK卸载与安装卸载:java-versionjavajavac判断jdk是否安装(显示版本号等信息,说明已经安装)whichjava(查看JDK的安装路径) rm-rfJDK地址(卸载JDK)  rm-rf/usr/java/jdk/jdk1.8.0_172/java-versionjavajavac查看是否卸载完毕vi命令编辑文件profile vi/etc/profile删除配置的环境变量…

    2022年6月15日
    34
  • SMTP协议分析[通俗易懂]

    感谢原作者:http://blog.csdn.net/bripengandre/article/details/2191048SMTP协议分析第1章.    SMTP概述1.1. SMTP在邮件通信中的位置SMTP,即简单邮件传送协议,所对应RFC文档为RFC821。同http等多数应用层协议一样,它工作在C/S模式下,用来实现因特网上的邮件传送。SMTP在整个电子邮件通

    2022年4月11日
    609
  • 报错注入详解_报错注入的过程

    报错注入详解_报错注入的过程报错注入报错注入是SQL注入的一种。利用前提:页面上没有显示位,但是需要输出SQL语句执行错误信息。比如mysql_error()优点:不需要显示位缺点:需要输出mysql_error()的报错信息报错函数1、floor报错注入floor()报错注入是利用count()、rand()、floor()、groupby这几个特定的函数结合在一起产生的注入漏洞,准确的说是floor,count,groupby冲突报错。报错原理:利用数据库表主键不能重复的原理,使用GROUPBY分组,产生主

    2022年9月30日
    5
  • 如何将InputStream转换为String

    2019独角兽企业重金招聘Python工程师标准>>>…

    2022年4月17日
    189
  • Java 面试之算法[通俗易懂]

    Java 面试之算法[通俗易懂]二分查找intBinarySearch(DataTypea[],intlow,inthigh,DataTypex){if(low>high){return-1;//查找失败}mid=(low+high)/2;//折半if(a[mid]==x){r…

    2022年7月18日
    24

发表回复

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

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