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


相关推荐

  • PHP面试-复习知识点整理

    PHP面试-复习知识点整理

    2022年2月10日
    48
  • 什么是redis

    什么是redis

    2021年10月18日
    52
  • es6数组常用函数方法

    es6数组常用函数方法//一,Array.from()将一组类似数组的对象转换为数组letsetx=newSet([1,2,3,4]);letarr=Array.from(setx);console.log(arr);//结果:[1,2,3,4]//二,Array.of(值1,值2,值3……)将一组值转换位数组leta=’12344′;letb=’2345′;le…

    2022年5月7日
    49
  • fastjson object转jsonobject_jsonobject取值

    fastjson object转jsonobject_jsonobject取值众所周知,kafka中存储的数据是经过BASE64加密后的jsonObject,因此从kafka中读取的数据经过base64解码,得到的是json串,利用JSONObect的方法可以对json串进行解析,拿到对应的数据。那么要如何将scala对象或者java对象转换为JsonObject对象或JSONObject对象呢?(注意:JsonObject对象和JSONObject对象不同,调用的API也…

    2022年10月5日
    5
  • DNS服务器的配置「建议收藏」

    DNS服务器的配置「建议收藏」DNS(DomainNameServer,域名服务器)是进行域名(domainname)和与之相对应的IP地址(IPaddress)转换的服务器。DNS中保存了一张域名(domainname)和与之相对应的IP地址(IPaddress)的表,以解析消息的域名。域名是Internet上某一台计算机或计算机组的名称,用于在数据传输时标识计算机的电子方位(有时也指地理位置)。1、安装…

    2022年6月4日
    43
  • python编程前景_Python前景如何,学完后可以从事方向?

    python编程前景_Python前景如何,学完后可以从事方向?前段时间浙江八年级新增了Python编程的课程,消息一出,引起了很多人的关注。连中学生都在学Python了,你还在犹豫要不要学习吗?对于想学Python,却又担心Python前景以及学完后可以从事方向的人,下面,小雷就给大家介绍一下。Python前景怎么样?目前国内外很多公司都在使用Python,例如搜索引擎Google的核心代码是Python完成的、迪士尼公司动画生成的Unix版本都内建了Pyt…

    2022年5月16日
    41

发表回复

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

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