Turning off authenticity token in Rails 2 for web services?

后端 未结 3 1667
旧时难觅i
旧时难觅i 2021-01-12 04:39

Instead of just filling out the form in HTML it should also be possible to just send a post request containing the params.. Is it possible to turn off the authenticity token

3条回答
  •  一生所求
    2021-01-12 05:36

    The request forgery protection works on the basis of checking the content-type of requests and it only checks the requests that can be made by a browser. No browser is able to generate a request with the content-type set to "application/json" for example. That's why the rails forgery protection routine won't check it. So, if you want to make a json request to your application, set the content-type header to "application/json" and it should work.

提交回复
热议问题