枚举 ContentType

    • 枚举常量详细资料

      • FORM_URLENCODED

        public static final ContentType FORM_URLENCODED
        标准表单编码,当action为get时候,浏览器用x-www-form-urlencoded的编码方式把form数据转换成一个字串(name1=value1&name2=value2…)
      • MULTIPART

        public static final ContentType MULTIPART
        文件上传编码,浏览器会把整个表单以控件为单位分割,并为每个部分加上Content-Disposition,并加上分割符(boundary)
      • JSON

        public static final ContentType JSON
        Rest请求JSON编码
      • XML

        public static final ContentType XML
        Rest请求XML编码
      • TEXT_PLAIN

        public static final ContentType TEXT_PLAIN
        text/plain编码
      • TEXT_XML

        public static final ContentType TEXT_XML
        Rest请求text/xml编码
      • TEXT_HTML

        public static final ContentType TEXT_HTML
        text/html编码
    • 方法详细资料

      • values

        public static ContentType[] values()
        按照声明该枚举类型的常量的顺序, 返回 包含这些常量的数组。该方法可用于迭代 常量, 如下所示:
        for (ContentType c : ContentType.values())
            System.out.println(c);
        
        返回:
        按照声明该枚举类型的常量的顺序返回的包含这些常量的数组
      • valueOf

        public static ContentType valueOf​(String name)
        返回带有指定名称的该类型的枚举常量。 字符串必须与用于声明该类型的枚举常量的 标识符完全匹配。(不允许有多余 的空格字符。)
        参数:
        name - 要返回的枚举常量的名称。
        返回:
        返回带有指定名称的枚举常量
        抛出:
        IllegalArgumentException - 如果该枚举类型没有带有指定名称的常量
        NullPointerException - 如果参数为空值
      • getByValue

        public static ContentType getByValue​(String value)
        根据枚举的value中获取枚举的对象
        参数:
        value -
        返回:
      • getValue

        public String getValue()
        获取value值
        返回:
        value值
        从以下版本开始:
        5.2.6
      • toString

        public String toString​(Charset charset)
        输出Content-Type字符串,附带编码信息
        参数:
        charset - 编码
        返回:
        Content-Type字符串
      • isDefault

        public static boolean isDefault​(String contentType)
        是否为默认Content-Type,默认包括null和application/x-www-form-urlencoded
        参数:
        contentType - 内容类型
        返回:
        是否为默认Content-Type
        从以下版本开始:
        4.1.5
      • isFormUrlEncode

        public static boolean isFormUrlEncode​(String contentType)
        是否为application/x-www-form-urlencoded
        参数:
        contentType - 内容类型
        返回:
        是否为application/x-www-form-urlencoded
      • get

        public static ContentType get​(String body)
        从请求参数的body中判断请求的Content-Type类型,支持的类型有:
         1. application/json
         1. application/xml
         
        参数:
        body - 请求参数体
        返回:
        Content-Type类型,如果无法判断返回null
      • build

        public static String build​(String contentType,
                                   Charset charset)
        输出Content-Type字符串,附带编码信息
        参数:
        contentType - Content-Type类型
        charset - 编码
        返回:
        Content-Type字符串
        从以下版本开始:
        4.5.4