In JQ, the HTTP Auth Basic authentication method can be directly placed in the AJAX parameters username and password, such as:
$.ajax ({
URL: "/datacenter/identification/queryinfo",
contentType: ' Application/json ',
dataType: " JSON ",
type:" POST ",
data:JSON.stringify ({' name ': Name, ' Idcard ': Idcard}),
username: ' O2ocredit ',
Password: ' 4xjfp5ifuhccg5y44eoj ',
}). Done (function (data) {
console.log (data.result.photobase64)
})
But in the angular can not directly pass the parameters, because the angular source code Xhr.open method does not open these two parameters into the mouth, so we need to auth certification in the header. Such as:
var username = ' O2ocredit ';
var password = ' 4xjfp5ifuhccg5y44eoj ';
var headers = {authorization: "Basic" + btoa (username + ":" + Password)};
$http ({method
: "POST",
URL: "/datacenter/identification/queryinfo
",
data:JSON.stringify ({ ' Name ': Name, ' Idcard ': Idcard}),
headers:headers
}
We can use this method to achieve our goal.