在调用API POST错误反应本土在终极版处理行动

问题描述 投票:1回答:1

我正在使用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)
        })
    }
};

上述被卡合误差和表示 - 语法错误:JSON解析错误:无法识别的令牌“<”

javascript json react-native react-redux multipartform-data
1个回答
0
投票

你的反应似乎并没有成为一个JSON。

更换

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

对于

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

而检查什么是错的错误之前的响应。

© www.soinside.com 2019 - 2024. All rights reserved.