Using an authorization header with Fetch in React Native

前端 未结 4 760
天涯浪人
天涯浪人 2020-11-27 10:18

I\'m trying to use fetch in React Native to grab information from the Product Hunt API. I\'ve obtained the proper Access Token and have saved it to State, but d

4条回答
  •  忘掉有多难
    2020-11-27 11:19

    Example fetch with authorization header:

    fetch('URL_GOES_HERE', { 
       method: 'post', 
       headers: new Headers({
         'Authorization': 'Basic '+btoa('username:password'), 
         'Content-Type': 'application/x-www-form-urlencoded'
       }), 
       body: 'A=1&B=2'
     });
    

提交回复
热议问题