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:
Frank-van-Puffelen
289

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 answer
3 points
Answered by:
Frank-van-Puffelen
289

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
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join