Which Java libraries do HTTP Accept Header Parsing? [closed]

微笑、不失礼 提交于 2019-12-05 10:52:33

问题


Which Java libraries parse HTTP Accept header?


回答1:


Have a look at the HttpClient Util.parseHeader method.


Edit: (trying to make this answer worth being accepted post-factum)

The spring framework provides this functionality within its MediaType component.

If you are already using Spring MVC you can simply request for a @RequestHeader-annotated parameter of type HttpHeaders and access the list of accepted media types by simply calling HttpHeaders.getAccept().




回答2:


You should read this article : http://www.xml.com/pub/a/2005/06/08/restful.html

The article uses Python but it's not a problem : at the end, the following link is shared : http://code.google.com/p/mimeparse

As you can see, "mimeparse" is :

Basic functions for handling mime-types in Erlang, JavaScript, Perl, PHP, Python, Ruby, Java

According to the home page :

List<String> mimeTypesSupported = Arrays.asList(StringUtils.split(
            "application/xbel+xml,text/xml", ','));
String bestMatch = MIMEParse.bestMatch(mimeTypesSupported, "text/*;q=0.5,*/*;q=0.1");


来源:https://stackoverflow.com/questions/7705979/which-java-libraries-do-http-accept-header-parsing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!