Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP 406 and 415 error codes

I am writing a web service that accepts only json, and also outputs only json.

So I need to return the appropriate status code if any other format is requested.

It appears that I have two choices:

  1. 406 - Not Acceptable
  2. 415 - Unsupported Media Type

It would be great if someone could enlighten me as to the semantics of the two codes.

like image 516
rmk Avatar asked Jul 20 '10 21:07

rmk


People also ask

What does HTTP 406 error mean?

The HyperText Transfer Protocol (HTTP) 406 Not Acceptable client error response code indicates that the server cannot produce a response matching the list of acceptable values defined in the request's proactive content negotiation headers, and that the server is unwilling to supply a default representation.

What does HTTP 415 error mean?

The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format.

How do I fix http error 415?

The 415 Unsupported Media Type error code usually indicates that the request entity has a media type that the server or resource does not support. The best way to fix the error is to make sure that you are sending the right Content-Type header value.


2 Answers

406 is returned by the server when it can't respond based on accepting the request headers (ie they have an Accept header which states they only want XML).

415 is returned by the server when the entity sent in a request (content in a POST or PUT) has an unsupported mediatype (i.e. they sent XML).

so.. 406 when you can't send what they want, 415 when they send what you don't want.

Hope that helps!

like image 198
nathan Avatar answered Sep 23 '22 06:09

nathan


  • 406 if an Accept header was sent you cannot fullfill.
  • 415 if a Content-Type is sent you cannot use.
like image 26
Wrikken Avatar answered Sep 23 '22 06:09

Wrikken