-1

I have an issue in using header in GET request in react native.

    await fetch(Global.base_url + 'discount/category_list', {
        method: 'GET',
        headers: {
            "Auth": Global.user_token,
            "Accept": 'application/json',
            "Content-Type": 'application/json',
        }
    })
    .then(response => response.json())
    .then(data => {
        if(data.status == 1) {
            Global.category_list = data.data;
        } else {
            Alert.alert("Warning!", 'Error');
        }

    })
    .catch(function(error) {
        Alert.alert('Warning!', 'Network error.');
    });

I can't get response. Invalid token response. But in post man, it works well. postman screenshot

Please advance me if anyone can solve this issue. Thanks

Water Flower
  • 377
  • 7
  • 23
  • Your syntax looks valid. Are you sure the Global.user_token is accessible and actually contains the token at that point ? – RDardelet Jul 02 '19 at 07:53
  • Thanks for your reply. Yes. and furthermore, I have tested with real token string. But don't work. – Water Flower Jul 02 '19 at 07:54
  • What’s the exact error message the browser logs in the devtools console? What’s the HTTP status code of the response? You can use the Network pane in browser devtools to check. What request headers is the browser actually sending? You can use the Network pane to check that too. – sideshowbarker Jul 02 '19 at 10:26

1 Answers1

0

Yes! your code is valid Check the api which got from global.

await fetch(Global.base_url + '/discount/category_list', {

I added '/' in the url before discount.

Try this

Allen Bert
  • 158
  • 2
  • 5
  • 20