【发布时间】:2017-07-15 04:03:40
【问题描述】:
我已经通过使用这样的 post 方法 api 成功创建了新记录(使用 Curl::PostField)
curl_post_fields = [
Curl::PostField.content('first_name', first_name),
Curl::PostField.content('last_name', last_name),]
contact = Curl::Easy.http_post("#{ENV['API_V1_URL']}/contacts", *curl_post_fields)
contact.ssl_verify_peer = false
contact.http_auth_types = :basic
contact.username = ENV['API_V1_USERNAME']
contact.password = ENV['API_V1_PASSWORD']
contact.perform
response = JSON.parse(contact.body_str)
但是当我通过像这样的补丁更新记录时(使用 json 请求参数):
contact = Curl.patch("#{ENV['API_V1_URL']}/contacts/#{qontak_id}",{:email => email, :gender_id => 8})
contact.ssl_verify_peer = false
contact.http_auth_types = :basic
contact.username = ENV['API_V1_USERNAME']
contact.password = ENV['API_V1_PASSWORD']
contact.perform
response = JSON.parse(contact.body_str)
我从服务器收到一些错误
Can't verify CSRF token authenticity
Filter chain halted as :authenticate rendered or redirected
我也关闭了 csrf protect_from_forgery with: :null_session
使用Curl::PostField 可能会自动包含csrf token,或者在patch or put method 中是否有类似Curl::Postfield 的方法?
【问题讨论】:
-
嗨,伙计们,我仍然坚持这一点,有什么帮助吗?
标签: ruby-on-rails curl csrf csrf-protection curb