gpt4 book ai didi

ruby-on-rails - rails : CSRF token not working but setup

转载 作者:数据小太阳 更新时间:2023-10-29 07:32:14 29 4
gpt4 key购买 nike

我在 heroku 上有我的 Rails 3 应用程序,当我发送银行信息时,我得到:警告:无法验证 CSRF token 真实性 但我的 CSRF token 已设置。 https://gist.github.com/anonymous/7081401

$.ajax({ url: '#{credit_cards_path}', 
type: 'POST',
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', '#{form_authenticity_token}')},
dataType: "json",
data: { cc_uri: response.data.uri,
address: $('.address').val()
// etc ...
},
success: function(randomobject) {
window.location = '/products/' + randomobject.value + '/receipt';
}
});

heroku 日志

829962+00:00 app[web.1]: Started POST "/products/2/card" for 100.2.109.97 at 2013-10-21 09:13:03 +0000
835379+00:00 app[web.1]: WARNING: Can't verify CSRF token authenticity
834929+00:00 app[web.1]: Processing by CreditcardsController#addcard as HTML
834929+00:00 app[web.1]: Parameters: {"state"=>"NY", "id"=>"2"}
604099+00:00 heroku[router]: at=info method=POST path=/products/2/card host=app.herokuapp.com fwd="100.2.109.97" dyno=web.1 connect=1ms service=1781ms status=500 bytes=643
604259+00:00 app[web.1]:
602739+00:00 app[web.1]: Completed 500 Internal Server Error in 1768ms
604259+00:00 app[web.1]: Balanced::BadRequest (Balanced::BadRequest(400)::Bad Request:: POST https://api.balancedpayments.com/v1/customers: request: Invalid field [card_uri] - "None" must be a string URI Your request id is OHMfe86f2883a3011e3980d02a1fe53e539. ):

最佳答案

可能与您对 #{form_authenticity_token} 的使用有关

根据此来源WARNING: Can't verify CSRF token authenticity rails您应该能够使用此代码:

headers: {
'X-Transaction': 'POST Example',
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},

关于ruby-on-rails - rails : CSRF token not working but setup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19503632/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com