我可以使用 POSTMAN 进行成功的API调用。但是,当从我的 react-app 调用具有相同配置的相同API时,会出现错误-
TypeError:“尝试获取资源时出现NetworkError。”
代码段如下:
var myHeaders = new Headers();
myHeaders.append("Authorization", API_TOKEN);
myHeaders.append("Content-Type", "application/json");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: data,
redirect: 'follow'
};
await fetch(API_URL, requestOptions)
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.log('error', error));