1

I'm using react-native 0.51.0. I have dozens of pages(components) where I make GET, POST requests. All works perfectly, except one of them. It seems, Authorization header does not pass during the call.

My request options are like

requestOptions = {
    method: 'GET',
    headers: {
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + this.props.token
    }
};

I get "Token not provided" error message when I run the code, but I try same token, exactly same request options through postmanand it works perfectly.

I surfed through lots of questions, issues and tried lots of suggested solutions like adding

access-control-allow-origin
credentials: 'same-origin
credentials: 'include'

But nothing changed.. I'm sure my token is true and not expired. Lots of suggestions are related with CORS thing. But what I do not understand, if true then why all other fetch methods work ? I call all http requests to the same server.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ali Zeynalov
  • 2,867
  • 8
  • 30
  • 54
  • guys. finally bug fixed. It was nothing related with front-end. I was doing everything right. developers on back-end side changed something with `url` and now it works. – Ali Zeynalov Apr 25 '18 at 15:06

1 Answers1

0

You could try this

fetch(API_URL, { 
  method: 'get', 
  headers: new Headers({requestOptions})
});

Source

Hope that helps.

Lucaci Sergiu
  • 564
  • 5
  • 17