我正在使用OData API,当我使用Postman进行GET请求时,一切正常,并且我得到了预期的响应。
但是当我从我的React应用程序使用fetch请求时,请求会抛出401错误,使用与我之前在Postman中使用的相同标头。并且它说:
这是我得到的401错误....
![Postman Request](https://istack.dev59.com/uOQnt.webp)
响应预检请求未通过访问控制检查:所请求的资源上没有“Access-Control-Allow-Origin”标头。因此,不允许来自“http://localhost:3000”的访问。响应的HTTP状态代码为401。
有任何解决这个问题的想法吗?
谢谢!
fetch('https://api4.successfactors.com/odata/v2/', {
method: 'GET',
headers: {
authorization: `Basic ${auth}`, //auth is the encoded base64 username:password
},
})
.then(response => response.json())
.then((response) => {
console.log('in response: ', response);
})
.catch((error) => {
console.log('in fetchJobs error: ', error);
});
![在此输入图片描述](https://istack.dev59.com/BVioz.webp)