为什么我会收到401?凭证是正确的。
app.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
$httpProvider.defaults.headers.common.Authorization = 'Basic ' + btoa("xxx:yyy");
$httpProvider.defaults.headers.common.withCredentials = true;
}
...
$http({
method: "POST",
url: url
data: data,
})
答案 0 :(得分:2)
尝试在Authorization
内添加$http
标题,如:
$http({
method: "POST",
url: url
data: data,
headers: {'Authorization': 'Basic ' + btoa("xxx:yyy")},
})