【问题标题】:angularjs ignored added headersangularjs忽略了添加的标题
【发布时间】:2014-03-26 12:07:17
【问题描述】:

我很想通过在this guide 之后向 google 发送身份验证码来获取 google api 令牌。

这是我的代码:

        $http({
            method: 'POST',
            url: 'https://accounts.google.com/o/oauth2/token',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            params : {
                code           : '4/heMv6ozWwCxS5RyTzCgThAgxvRyk.oske-bNEGOUTOl05ti8ZT3YnwwH8iQI',
                client_id      : GoogleAppInfo.clientId,
                 redirect_uri  : GoogleAppInfo.redirect_uri,
                client_secret  : GoogleAppInfo.client_secret,
                grant_type     : 'authorization_code'
            }

        }).
        success(function(data, status, headers, config) {
            alert('secsses');
        }).
        error(function(data, status, headers, config) {
            alert('error');

        });

请求已发送,但未设置标头!

有谁知道问题出在哪里?

【问题讨论】:

  • 你真的发送了吗?您似乎正在发送跨域请求。
  • 是的。我发送了请求,这是我收到错误响应后来自 Firefox 控制台的请求。

标签: angularjs xmlhttprequest


【解决方案1】:

发件人:Angular, content type is not being sent with $http

“您需要在请求中包含正文。否则,Angular 会删除内容类型标头。

data: '' 添加到$http 的参数中。"

【讨论】:

  • 谢谢!那行得通。添加了标题。但它并没有解决问题。谷歌服务器仍然返回错误的请求错误。
  • 我建议添加另一个可能带有不同标签的问题,因为问题已经转移到与谷歌服务器的通信。抱歉,我没有这方面的经验。
  • 好吧,我没有。谢谢您的帮助。我的另一个问题是*.com/questions/22661673/…