Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error HTTP Status 406: @ResponseBody not returning data

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
like image 528
kajarigd Avatar asked Mar 22 '23 20:03

kajarigd


1 Answers

I faced this error and when I removed .html suffix which was mistakenly added to the request URL, this error got resolved!

like image 117
James Jithin Avatar answered Apr 01 '23 03:04

James Jithin