我必须使用基本授权访问API,
请注意,我无权访问存储API的服务器。我无法修改api并使用ASP.net创建
我在提供凭据后访问浏览器上的api网址时可以查看json数据,
然而,当我试图通过AJAX请求检索数据时 我收到此错误
OPTIONS https://apis url/HR/api/employees 405 (Method Not Allowed)
XMLHttpRequest cannot load https://apis url/HR/api/employees.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://xxx.xx.xx.xx' is therefore not allowed access. The response had HTTP status code 405.
如何以任何合法方式检索json数据?
这是我的代码
function getDataF()
{
var _token = $("input[name='_token']").val();
$.ajax({
xhrFields: {
withCredentials: true
},
headers: {
'Authorization': "Basic encryptedvalue_here"
},
url: 'https://apis url/HR/api/employees',
type: 'GET',
dataType: 'json',
contentType: "application/json",
success: function(response){
console.log(response);
}
});
}