$ HTTP POST不会在Safari工作 [英] $http post not working in Safari

查看:1005
本文介绍了$ HTTP POST不会在Safari工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序AngularJS,我已经实现了一个简单的登录API调用。该API给我除了在Safari在所有浏览器的响应。

I am developing an AngularJS app and I've implemented a simple login API call. The API gives me a response in all browsers except in Safari.

我的登录API调用看起来像这样

My login API call looks like this

$http.post(config.login, {
        email: username,
        password: password
    })
    .then(function (response) {
            callback(response);
        },
        function (response) {
            callback(response);
        });

我得到在Safari以下响应。

I get the following response in Safari.

在这里输入的形象描述

我使用的角度V1.4.8一个Safari浏览器9.0版(11601.1.56)

I am using Angular v1.4.8 a Safari Version 9.0 (11601.1.56)

这是怎么回事不对任何线索?

Any clue on whats going wrong?

推荐答案

这让我疯了。
第一件事情,我下载angular.js文件,然后搜索xhr.setRequestHead。所有的问题都在这里。
我试图把一些日志,看看发生了什么事。

This makes me crazy. First thing, I download angular.js file, then search for "xhr.setRequestHead". All problems are here. I've tried to put some logs to see what was happening.

forEach(headers, function(value, key) {
    key = key.trim();// trim the key
    value = value.trim();// trim the value
    console.log("******************** key: " + key);
    console.log("******************** value: " + value);
    console.log('value: Basic vs ' + value+ ' equal: '+ (value==="Basic"));
    console.log('value.length: ' + value.length);
    if (isDefined(value)) {
         xhr.setRequestHeader(key, value);
    }
});

我发现angularjs自动将头'授权':在基本但基本字符串的长度为6而不是5。
因此,使用键= key.trim()和值= value.trim()解决了问题。

I found that angularjs automatically put header 'Authorization':'Basic' in. But the length of 'Basic' string is 6 not 5. So using key = key.trim() and value = value.trim() solves problem.

让我知道,如果这种帮助。

Let me know if this help.

这篇关于$ HTTP POST不会在Safari工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆