I have the following code in REST, Spring MVC. This code is supposed to return a JSON type data structure called ResponseText:
@RequestMapping(value="/movieTheater", headers = {"ACCEPT=*/*"}, method=RequestMethod.GET)
public @ResponseBody ResponseText getCustomerInput(@RequestParam("name") String name, @RequestParam("price") Double price) {
Transaction transaction = new Transaction();
ResponseText result = new ResponseText();
transaction.setMovieName(name);
transaction.setTicketPrice(price);
transaction.setDatetime(new Date());
if(transactionService.addTransaction(transaction))
result.setMessage(ResponseStatus.SUCCESS.getStatus());
else
result.setMessage(ResponseStatus.FAILED.getStatus());
return result;
}
But when I am executing this code via the below URL in the browser, I am getting the below error:
URL:
http://localhost:8080/SpringMVCMerchant/movieTheater.htm?name=Smurfs&price=300.00
Error:
HTTP Status 406 -
type Status report
message
description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
I am unable to identify what I am doing wrong here. I looked up on the Net explaining this error, but still don't know what I am missing. I have given ACCEPT="/", which is supposed to cover all sorts of responses, right? Please help! Thanks in advance!
** When I added the header
headers={"Accept: application/json, text/javascript"}
instead of the above one, I got the following error:
HTTP Status 405 - Request method 'GET' not supported
I faced this error and when I removed .html
suffix which was mistakenly added to the request URL, this error got resolved!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With