【发布时间】:2018-03-01 14:03:09
【问题描述】:
我正在使用 odata api,当我使用邮递员发出 GET 请求时,效果很好,并且我得到了预期的响应。
但是,当我从我的 React 应用程序中使用 fetch 请求时,该请求会引发 401,使用的标头与我之前在 Postman 中使用的标头相同。它说Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 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);
});
【问题讨论】:
标签: javascript get request odata fetch-api