【发布时间】:2019-01-27 12:50:45
【问题描述】:
哪些 Java 库解析 HTTP Accept 标头?
【问题讨论】:
标签: java http http-headers
哪些 Java 库解析 HTTP Accept 标头?
【问题讨论】:
标签: java http http-headers
您应该阅读这篇文章:http://www.xml.com/pub/a/2005/06/08/restful.html
文章使用Python但没问题:最后分享如下链接:http://code.google.com/p/mimeparse
如您所见,“mimeparse”是:
在 Erlang、JavaScript、Perl、PHP、Python、Ruby、Java
中处理 mime 类型的基本函数
根据主页:
List<String> mimeTypesSupported = Arrays.asList(StringUtils.split(
"application/xbel+xml,text/xml", ','));
String bestMatch = MIMEParse.bestMatch(mimeTypesSupported, "text/*;q=0.5,*/*;q=0.1");
【讨论】:
看看 HttpClient Util.parseHeader 方法。
编辑:(试图让这个答案值得事后接受)
spring 框架在其MediaType 组件中提供了此功能。
如果您已经在使用 Spring MVC,您可以简单地请求 @RequestHeader 类型的注释参数 HttpHeaders 并通过调用 HttpHeaders.getAccept() 访问接受的媒体类型列表。
【讨论】: