Is the Content-Type header suitable for any HTTP verb other than PUT or POST?

I am testing the CollectionSpace software's REST API and notice that sending a Content-Type header as part of a GET request results in the following error:

HTTP Status 415 - Cannot consume content type

Both python REST client libraries I tried, restclient on github and python-rest-client in google code send Content-Type header when executing GET requests.

My understanding from the consideration of http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html is that clients should only send Content-Type headers for POST and PUT requests. It's right?

The fact that both of these libraries send a header makes me think that servers usually ignore it and not return a client error code.

+3
source share
2 answers

Although this is not explicitly stated in the specification, some conclusions can be drawn. Section 7.2.1 states

Any HTTP / 1.1 message containing an entity-body MUST include a Content-Type header field that defines the media type of this body.

This is pretty obvious and makes sense. Given this, we can take a look at section 9 (method definitions) to see which ones mention that they can have an entity in the body query. Three of them mention this:

OPTIONS

If the OPTIONS request includes (as indicated by Content-Length or Transfer-Encoding) ...

Post

... used to request that the origin server accepts an object enclosed in the request ...

Put

... , Request-URI

, TRACE:

TRACE .

( TRACE) Content-Type. , , , , .


, , HTTP- 415, .

4.3 :

... , .

GET, .

, , Content-Length ( Transfer-Encoding "" ), , , Content-Type . , 4.4.

+5

415

, REST @Consumes, MIME. , "" "/" " ". MockHttpRequest RESTEasy

request.accept(MediaType.APPLICATION_JSON); request.contentType(MediaType.APPLICATION_JSON);

+2

Source: https://habr.com/ru/post/1786791/


All Articles