content-negotiation

Is HTTP content negotiation being used by browsers and servers in practice?

删除回忆录丶 提交于 2019-12-08 04:05:20
问题 I'm learning about HTTP content negotiation at the moment. I already understand the basic way client and server are able to negotiate a representation for the content requested. I could not find out, though, what content negotiation is actually good for . Are real world browsers actively using any of this? I understand they are sending some headers such as Accept but their content and meaning seems vaguely defined to be. I also wonder if real-world web applications can make use of HTTP

What are the Pros and Cons of using URI vs Accept Headers for REST content format negotiation?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 12:23:11
问题 Based on info in the following question REST Content-Type: Should it be based on extension or Accept header?, I'm aware either custom URIs or specifying Accept Headers are 'acceptable' (pun intended) methods for for a REST-ish web service to determine response format for the client. However, a lot of big names seem to use the custom URI method with their APIs. What are the strengths of one way over the other? 回答1: In REST, URIs are intended to identify only a resource. Content negotiation is

How do I configure the status code returned by my ASP.NET Web API service when the request has an unsupported Content-Type?

ⅰ亾dé卋堺 提交于 2019-12-07 08:20:49
问题 If a request is made to my Web API service that has a Content-Type header containing a type not supported by that service, it returns a 500 Internal Server Error status code with a message similar to the following: {"Message":"An error has occurred.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'MyDto' from content with media type 'application/UnsupportedContentType'.","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Net.Http

Does HTTP content negotiation respect media type parameters

拜拜、爱过 提交于 2019-12-05 16:46:51
An HTTP request can include an Accept header, indicating the media type(s) of responses that the client will find acceptable. The server should honour the request by providing a response that has a Content-Type that matches (one of) the requested media type(s). A media type may include parameters . Does HTTP require that this process of content-negotiation respect parameters ? That is, if the client requests Accept: application/vnd.example; version=2 (here the version parameter has a value of 2 ), and the server can serve media-type application/vnd.example; version=1 , but not application/vnd

How do I configure the status code returned by my ASP.NET Web API service when the request has an unsupported Content-Type?

孤人 提交于 2019-12-05 16:40:54
If a request is made to my Web API service that has a Content-Type header containing a type not supported by that service, it returns a 500 Internal Server Error status code with a message similar to the following: {"Message":"An error has occurred.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'MyDto' from content with media type 'application/UnsupportedContentType'.","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters,

Serving RDF representation of Java model with Spring MVC?

此生再无相见时 提交于 2019-12-04 15:01:16
How can I serve an RDF representation of a Java model via Spring MVC? I have JSON and XML representations working using Spring's content negotiation mechanisms and would like to do the same for RDF. Assuming that you are using annotation driven configuration for your MVC application, this actually could be quite simple. Using the W3C's Media Types Issues for Text RDF Formats as a guide for content type specification, it's quite easy to augment your existing solution. The real question is what is your desired serialization type when a request for RDF is made? If we are utilizing Jena as the

How to redirect users based on browser language

时光毁灭记忆、已成空白 提交于 2019-12-04 07:57:01
I want to redirect users based on browser language, I figured out how to do this here, it works fine, here is the code(PHP): if(preg_match('/en-US/', $_SERVER['HTTP_USER_AGENT'])) header("location:index.php"); else header("location:http://cn.gearor.com"); The problem is I only want to redirect users from other websites or at the first visit to my website. Which means I don't want users reading some pages of my website, when they go back to index, they were redirect to other page. And I also have a link in my website, like: English or Chinese, when users click English from a Chinese page, they

ASP.NET MVC 4 / Web API - insert Razor renderer for Accepts: text/html

假如想象 提交于 2019-12-03 12:54:46
I am creating a RESTful Web Service using ASP.NET MVC 4 Web API. For API access, I am returning JSON, though once I get everything working correctly, the content negotiation should work for XML and JSON by default. Since I am working towards a truly RESTful resource-centric web service, my URI's will be pointing to actual resources. I would like to take advantage of that by returning an HTML representation of the resource if Accepts: text/html comes in the request (like throwing the link in a browser). I would like to be able to take advantage of MVC 4 Web API's content negotiation to insert a

Spring 3.2 content negotiation class cast exception

走远了吗. 提交于 2019-12-03 10:16:52
问题 We develop a standard Java web application using Spring MVC, and have recently tried to upgrade from 3.0.6 to 3.2.0. Nearly of all our servlet responses are JSP or Json views, but there are some that are pdf requests, with extension 'pdf'. In Spring 3.0.6 we had this set up, taken from the Spring MVC documentation. <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="mediaTypes"> <map> <entry key="pdf" value="application/pdf"/> <entry key="html"

Spring 3.2 content negotiation class cast exception

放肆的年华 提交于 2019-12-03 00:44:54
We develop a standard Java web application using Spring MVC, and have recently tried to upgrade from 3.0.6 to 3.2.0. Nearly of all our servlet responses are JSP or Json views, but there are some that are pdf requests, with extension 'pdf'. In Spring 3.0.6 we had this set up, taken from the Spring MVC documentation. <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="mediaTypes"> <map> <entry key="pdf" value="application/pdf"/> <entry key="html" value="text/html"/> <entry key="json" value="application/json"/> </map> which worked fine, in