簡體   English   中英

通過處理Redux中的操作在React Native中調用POST API時出錯

[英]Error in calling POST api in react native by handling action in redux

我正在使用POST api調用來獲取一些數據,其中有數據和標頭的令牌值,但是響應不佳,我檢查了許多文檔,但無法弄清楚錯誤,這是代碼:

export const shareUserProfileHandler = (sharedReceiverData) => {
    return dispatch => {
        let formData = new FormData();
        for (let key in sharedReceiverData) {
            formData.append(key, sharedReceiverData[key]);
        }
         let requestConfig = {
             method: 'POST',
             headers: {
                 'Accept': 'application/json',
                 'Content-Type': 'multipart/form-data',
                 'Authorization': 'Token 97a74c03004e7d6b0658b14ddb'
             },
             body: formData
         };

        fetch(`http://api.com`, requestConfig)
        .then(response => response.json())
        .then(response => {
            alert('share user card api worked')

        })
        .catch(error => {
            alert('api error ' + error)
        })
    }
};

上面是捕獲錯誤並顯示-SyntaxError:JSON解析錯誤:無法識別的令牌“ <”

您的響應似乎不是JSON。

更換

.then((response) => response.json())

對於

.then((response) => { console.log('response', response); response.json() })

並檢查錯誤之前響應的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM