I am trying to access an API which which does not require authentication. When I use jQuery, my request works fine, but when requesting in React Native, I get Can't verify CSRF token authenticity
. I have tried many ways to post with this token, but can't seem to figure it out.
My code is:
fetch(url, {
method: 'patch',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: body,
})
答案 0 :(得分:0)
您需要在请求中设置X-CSRF-Token
标头,或禁用跨站点请求伪造(CSRF)保护。以下是一些可以帮助您的链接:
http://api.rubyonrails.org/classes/ActionView/Helpers/CsrfHelper.html#method-i-csrf_meta_tags
答案 1 :(得分:0)
对于CORS请求,请使用" include"允许将凭据发送到其他域的值:
fetch(url, {
method: 'patch',
credentials: 'include'
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: body,
})