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


相关推荐

  • linux 挂载磁盘阵列[通俗易懂]

    linux 挂载磁盘阵列[通俗易懂]1、fdisk-l查看磁盘系统磁盘,若提示bash:fdisk:commandnotfound这是因为fdisk没有在搜索路径中,我们需要:#echo$PATH/usr/kerberos/sbin再查看fdisk命令再哪个目录下:#whereisfdiskfdisk:/sbin/fdi…

    2022年6月19日
    38
  • CriticalSection_protection initialization

    CriticalSection_protection initialization如果EnterCriticalSection将一个线程置于等待状态,那么该线程在很长时间内就不能再次被调度。实际上,在编写得不好的应用程序中,该线程永远不会再次被赋予CPU时间。TryEnterCriticalSection函数决不允许调用线程进入等待状态。它的返回值能够指明调用线程是否能够获得对资源的访问权。TryEnterCriticalSection发现该资源已经被另一个线程访问,它就返回F

    2022年9月20日
    4
  • Laravel5.3使用学习笔记—中间件

    Laravel5.3使用学习笔记—中间件

    2021年10月22日
    50
  • MTP模式与USB存储模式(MTP in Android)「建议收藏」

    MTP模式与USB存储模式(MTP in Android)「建议收藏」转载:http://bbs.meizu.cn/thread-4747416-1-1.htmlMTPinAndroidMTP的全称是MediaTransferProtocol(媒体传输协议),它是微软公司提出的一套媒体文件传输协议。Android从3.0开始支持MTP。不过,在今天的智能手机领域内,Google和微软是一对冤家,为什么Android中会使用MTP呢?请看下文。一背景知…

    2022年4月20日
    117
  • Sql Prompt安装图文教程「建议收藏」

    Sql Prompt安装图文教程「建议收藏」一、概念SQLPrompt是一款拥有SQL智能提示功能的SQLServer和VS插件。SQLPrompt能根据数据库的对象名称,语法和用户编写的代码片段自动进行检索,智能的为用户提供唯一合适的代码选择。自动脚本设置为用户提供了简单的代码易读性–这在开发者使用的是不大熟悉的脚本时尤其有用。SQLPrompt是立即可用的且能极大的提高生产率。…

    2022年7月14日
    98
  • win10中PHPstorm 里面Terminal 不能使用 esc键吗退出编辑模式吗

    win10中PHPstorm 里面Terminal 不能使用 esc键吗退出编辑模式吗

    2022年2月19日
    25

发表回复

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

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