Status 415 unsupported media type

I have following controller:

and I make following request in postman:

text from error:

What the reason of the problem and how to send request correct?

instead of Long and pass json( <"timeout":"2">) — it works correct

5 Answers 5

When reading json your content type should be application/json.

if you need to use application/json type and write below code in controller method :-

@RequestBody is used to deserialize JSON to POJO . If you need to submit form data to the controller try something like

In your request you are sending the timeout property in a multipart/form-data body. In postman, select option ‘raw’ for the body and set the content type to application/json. Then enter the following as body content:

You should also set the consumes MediaType on your controller. (Although it could be that it automatically resolves to json) For example:

There is no need to add a content-type header manually. You are overriding the value set by Postman. Just select form-data in POST request and send your request to see if it works.

I am calling REST service with JSON request and it gives Http 415 "Unsupported Media Type" error.

Request content type is set to ("Content-Type", "application/json; charset=utf8").

It works fine if I don’t include Json object in the request. I am using google-gson-2.2.4 library for json.

I tried using a couple of different libraries but it made no difference.

Can anybody please help me to resolve this?

На этой странице

Код ответа на ошибку клиента HTTP 415 Unsupported Media Type указывает, что сервер отказывается принять запрос, потому что формат содержимого не поддерживается сервером.

Читайте также:  Default programs editor как пользоваться

Проблема формата может быть связана с указанным запросом Content-Type или Content-Encoding или в результате непосредственного контроля данных.

Rate this post

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *