Top community members

If you think it is valuable to share IT knowledge and help others.

It is the right place for you. ❤ 💻

Join our community.

Spring - HTTP Status 415 - The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

1 points
Asked by:
Ticket Ninja
2338

I have created some controller that returns some result for indicated GET REST action:

http://localhost:8080/rest/description

With jQuery AJAX GET method it works perfectly, but when I tried to open same url from browser I got following problem:

HTTP Status 415 -
type Status report

message

description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

Apache Tomcat/8.0.46

Screenshot:

My controller looks following way:

@Controller
public class PostMainRestController {
    
    @RequestMapping(
            value = "/rest/description",
            method = RequestMethod.GET,
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    @ResponseBody
    @Transactional(readOnly = true)
    public String getDescription(HttpServletRequest request) {

        return "[\"This is my description.\"]";
    }
}

 

1 answers
3 points
Answered by:
Ticket Ninja
2338

The problem is related with your consumes parameter.

GET method is used and you send nothing.

Remove consumes. Check below solution:

@Controller
public class PostMainRestController {
    
    @RequestMapping(
            value = "/rest/description",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    @ResponseBody
    @Transactional(readOnly = true)
    public String getDescription(HttpServletRequest request) {

        return "[\"This is my description.\"]";
    }
}

 

0 comments Add comment

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more