我开发一个应用程序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.
相关推荐
最新文章