Languages

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:
Marcin
2535

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:
Marcin
2535

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
Hey 👋
Would you like to know what we do?
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.