简体   繁体   English

如何解决Postman的InvalidAuthenticityToken错误?

[英]How do I solve InvalidAuthenticityToken error from Postman?

I'm running postman to send requests to my rails server. 我正在运行邮递员,将请求发送到我的Rails服务器。 I am facing authenticity token issues when sending POST requests to create new objects. 发送POST请求以创建新对象时,我面临真实性令牌问题。 I need to be able to send all requests across the server and add the necessary authentications to a Postman environment. 我需要能够跨服务器发送所有请求,并将必要的身份验证添加到Postman环境。

If you're creating an API and want to accept requests from other domains you'll need to disable this security filter. 如果您要创建API并希望接受来自其他域的请求,则需要禁用此安全过滤器。

To do it add this to your controller : 为此,将其添加到您的控制器中:

skip_before_action :verify_authenticity_token, only: :your_post_action

You can disable it only for json requests, see this answer: https://stackoverflow.com/a/22715175/8352929 您只能对json请求禁用它,请参见以下答案: https : //stackoverflow.com/a/22715175/8352929

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM