REST、Spring MVC に次のコードがあります。このコードは、ResponseText と呼ばれる JSON 型のデータ構造を返すことになっています。
@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;
}
しかし、ブラウザで以下の URL を介してこのコードを実行すると、以下のエラーが発生します。
URL:
http://localhost:8080/SpringMVCMerchant/movieTheater.htm?name=Smurfs&price=300.00
エラー:
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.
ここで何が間違っているのかを特定できません。このエラーを説明するためにネットを調べましたが、何が欠けているのかまだわかりません。ACCEPT=" / " を指定しましたが、これはあらゆる種類の応答をカバーするはずですよね? 助けてください!前もって感謝します!
** ヘッダーを追加したとき
headers={"Accept: application/json, text/javascript"}
上記の代わりに、次のエラーが発生しました。
HTTP Status 405 - Request method 'GET' not supported