i托盘可以访问端点并获取令牌,但是我有一个错误: 从源'http:localhost:51780'对'https://ptyi.test.com:8443/users/authenticate'处XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:否'Access Control-Allow-Origin;标头出现在请求的资源上。我该如何解决?为什么通过邮递员访问?在此先感谢!!
$.ajax({
type:"POST",
url: "https://ptyi.test.com:8443/users/authenticate",
data: { username :"test@sur.com" , password : "ff12dfb3L$"},
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert(result)
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + " \n" + xhr.responseText, "\n" + thrownError);
},
});
});
答案 0 :(得分:-1)
出于安全原因,您无法向在不同端口上运行的端点调用ajax请求。 我不知道您的服务器端技术是什么,但是 如果您有权访问https://ptyi.test.com:8443/users/authenticate的源代码,则可以添加 Access-Control-Allow-Origin“,” *“
var performingMath = false