1

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,
})

2 Answers2

0

You need to set the X-CSRF-Token headers in your request, or disable Cross Site Request Forgery (CSRF) protection. Here are some links that will help you:

http://api.rubyonrails.org/classes/ActionView/Helpers/CsrfHelper.html#method-i-csrf_meta_tags

Turn off CSRF token in rails 3

Daniel Westendorf
  • 3,375
  • 18
  • 23
0

For CORS requests, use the "include" value to allow sending credentials to other domains:

fetch(url, {
  method: 'patch',
  credentials: 'include'
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: body,
})
Starmetal
  • 740
  • 6
  • 14