[英]Angular post request to google got stuck by CORS
Url : http://local.m2.xxx.com/login 网址: http : //local.m2.xxx.com/login
this.$http.post('https://accounts.google.com/o/oauth2/token', {
'code': code,
'redirect_uri': '***',
'client_id': '******',
'client_secret': '****',
'grant_type': 'authorization_code'
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.success((data, status, headers, config)=> {
deferred.resolve(data);
})
.error((data, status) => {
deferred.reject(data);
});
I also set Authorized JavaScript origins as http://local.m2.xxx.com 我还将“授权JavaScript”来源设置为http://local.m2.xxx.com
but still getting XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/token . 但仍然获取XMLHttpRequest无法加载https://accounts.google.com/o/oauth2/token 。 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. 对预检请求的响应未通过访问控制检查:请求的资源上不存在“ Access-Control-Allow-Origin”标头。 Origin '***' is therefore not allowed access. 因此,不允许访问来源“ ***”。 The response had HTTP status code 405. 响应的HTTP状态码为405。
Cant find the solution 无法找到解决方案
You shouldn't post to that url. 您不应该发布到该网址。 Instead you should just redirect your browser to it, or open it in a popup window. 相反,您应该将浏览器重定向到该浏览器,或在弹出窗口中将其打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.