package foundation.icall;
|
|
import foundation.util.Util;
|
|
public enum ContentType {
|
|
TextPlain("text/plain"), //纯文本格式,空格转换为 “+” 加号,但不对特殊字符编码
|
ApplicationJson("application/json"), //用来告诉服务端,消息主体是序列化后的JSON字符串
|
ApplicationFormDataUrlencoded("application/x-www-form-urlencoded"), //参数为键值对形式,在发送前编码所有字符(默认)
|
MultipartFormData("multipart/form-data"), //参数为键值对形式,不编码
|
TextHtml("text/html"), //HTML格式
|
TextXml("text/xml"), //XML格式
|
TextXMarkdown("text/x-markdown"), //Markdown格式
|
ImageGif("image/gif"), //gif图片格式
|
ImageJpeg("image/jpeg"), //jpg图片格式
|
ImagePng("image/png"), //png图片格式
|
ApplicationXhtmlXml("application/xhtml+xml"), //XHTML格式
|
ApplicationXml("application/xml"), //XML数据格式
|
ApplicationPdf("application/pdf"), //pdf格式
|
ApplicationMsword("application/msword"), //Word文档格式
|
ApplicationOctetStream("application/octet-stream"), //二进制流数据(如常见的文件下载)
|
Unknown("unknown");
|
|
private String code;
|
|
private ContentType(String code) {
|
this.code = code;
|
}
|
|
public static ContentType parse(String code) {
|
if (Util.isEmpty(code)) {
|
return Unknown;
|
}
|
|
code = code.toLowerCase();
|
|
for (ContentType contentType : ContentType.values()) {
|
if (contentType.getCode().equalsIgnoreCase(code)) {
|
return contentType;
|
}
|
}
|
|
return Unknown;
|
}
|
|
public String getCode() {
|
return code;
|
}
|
}
|
|