Weird “406 not acceptable” error

前端 未结 12 1176
南方客
南方客 2020-11-27 05:38

When I try to hit this action via Javascript, I get a 406 Not Acceptable error:

  def show
    @annotation = Annotation.find_by_id(params[:id])
         


        
12条回答
  •  孤街浪徒
    2020-11-27 06:05

    This happened to me when using HTTPRiot connecting to a JSON rendering web app from an iPhone app. It appears that the issue is due to Rails expecting an Accept HTTP header that it is well, comfortable with. As such, I used Firefox's LiveHTTPHeaders extension to see what headers work without a 406. In any case the Accept string that worked was:

    text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    

    Another area that I would examine is the JSON-producing controller. If the controller is missing a format directive to specify it can return JSON in response, that too may cause a 406 error.

提交回复
热议问题