When using mode: no-cors for a request, browser isn’t adding request header I’ve set in my frontend code

前端 未结 2 1864
眼角桃花
眼角桃花 2020-12-21 21:55

in my React app, I have the following API POST to allow the user to edit their profile (name and image).

  static updateProfile(formData, user_id) {
    cons         


        
2条回答
  •  被撕碎了的回忆
    2020-12-21 22:18

    By using below code you can make a fetch request with Authorization or bearer

        var url = "https://yourUrl";
        var bearer = 'Bearer '+ bearer_token;
        fetch(url, {
        method: 'GET',
        withCredentials: true,
        credentials: 'include',
        headers: {
            'Authorization': bearer,
            'X-FP-API-KEY': 'iphone',
            'Content-Type': 'application/json'}
        }).then((responseJson) => {
            var items = JSON.parse(responseJson._bodyInit);
        })
        .catch(error => this.setState({
        isLoading: false,
        message: 'Something bad happened ' + error
        }));
    

提交回复
热议问题