Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
686 views
in Technique[技术] by (71.8m points)

web services - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...