【问题标题】:Angular post request to google got stuck by CORS对谷歌的 Angular 发布请求被 CORS 卡住了
【发布时间】:2016-04-26 15:50:03
【问题描述】:

网址: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);
            });

我还将 Authorized JavaScript origins 设置为 http://local.m2.xxx.com

但仍收到 XMLHttpRequest 无法加载 https://accounts.google.com/o/oauth2/token。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin '***' 不允许访问。响应的 HTTP 状态代码为 405。

找不到解决办法

【问题讨论】:

标签: javascript angularjs xmlhttprequest google-login


【解决方案1】:

您不应发布到该网址。相反,您应该将浏览器重定向到它,或者在弹出窗口中打开它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-03
    • 2021-03-19
    • 2019-02-06
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    • 1970-01-01
    • 2021-02-19
    相关资源
    最近更新 更多