[英]ERROR : No 'Access-Control-Allow-Origin' header is present on the requested resource
[英]MIcrosoft PowerBi React Access Token Error No 'Access-Control-Allow-Origin' header is present on the requested resource
我试图在我的 react 应用程序中获取 microsoft powerbi 访问令牌,它显示错误 No 'Access-Control-Allow-Origin' header is present on the requested resource 当我使用 fetch 时。 您可以在下面找到我尝试过的内容:-
useEffect(() => {
let accessTokenData = {
'grant_type':'password',
'username':'******',
'password':'******',
'client_id': '**********',
'client_secret': '********',
'resource': 'https://analysis.windows.net/powerbi/api'
}
let formbody = [];
for (let property in accessTokenData) {
let encodedKey = encodeURIComponent(property);
let encodedValue = encodeURIComponent(accessTokenData[property]);
formbody.push(encodedKey + "=" + encodedValue);
}
formbody = formbody.join("&");
fetch(`https://login.microsoftonline.com/common/oauth2/token`, {
// mode: 'no-cors',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
body: formbody
})
.then( data => data.json())
.then(
data => {
setAccessToken(data)
console.log(data['access_token'])
}
)
.catch( error => console.error(error))
}, []);
如果您有处理此问题的经验或从事过类似工作,请您在这方面指导我。
这个错误是由于cors,检查线程上的类似问题 - github.com/jaredhanson/passport/issues/582
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.