0

我有大量 JSON 文件,并希望通过我的表单自动发布它们。我通过 curl 尝试过:

curl -d "startup[name]='test startup'" -d "startup[url]='http://startup.com'" -d "startup[category]=['','Analytics']" -d "startup[founded(1i)]='2013'" -d "startup[founded(2i)]='5'" -d "startup[founded(3i)]='1'" -d "startup[description]='blah'" http://localhost:5000/startups

但我得到一个 HTML 响应,上面写着ActionController::InvalidAuthenticityToken

我怎样才能轻松地自动化我的 POST。如果我可以在 Ruby 中更轻松地做到这一点,我很想听听如何。

4

2 回答 2

2

您可以逐个控制器禁用 csrf 保护:

skip_before_filter :verify_authenticity_token

将上面的行添加到StartupsController,现在表单将提交

于 2013-05-09T05:27:41.103 回答
1

我认为您应该首先对新操作发出获取请求,例如

http://localhost:5000/startups/new

然后解析 html 以找出真实性令牌,将其用作 POST 请求的参数之一

于 2013-05-09T05:28:40.030 回答