当向我的服务发送 http.post 请求时,我首先发送一个 Option 请求(根据 Cors 的要求)。
然而我已经意识到我的OPTIONS(飞行前)请求返回否response.data
在其回应中,但我的POST请求是。这带来了一个问题,因为我需要访问response.data
来自POST回复...
Angular 是否允许我们以某种方式丢弃 OPTIONS 响应http.post
call?
$http.post("http://api.worksiteclouddev.com/RestfulAPI/api/vw_PeopleListSiteAccess_Update/Get/", JSON.stringify(vm.content))
.then(function (response) {
//success
vm.person = {
"firstname": response.data.Firstname,
"surname": response.data.surname
};
console.log(response.data);
},
function (error) {
//failure
console.log("Something went wrong..." + error.status);
})
.finally(function () {
vm.ptsnumber = "";
});
Chrome responses:
您不能放弃预检 OPTIONS 请求。
此请求的目的是向服务器请求发出实际请求的权限。您的预检响应需要确认这些标头才能使实际请求发挥作用。
当您跨不同来源发出请求时,它们是必要的。
此飞行前请求是由某些浏览器作为安全措施发出的,以确保正在执行的请求受到服务器的信任。这意味着服务器知道根据请求发送的方法、来源和标头可以安全地执行操作。
在你的情况下,你应该在 api 响应后得到响应
$http.post(
"http://api.worksiteclouddev.com/RestfulAPI/api/vw_PeopleListSiteAccess_Update/Get/", JSON.stringify(vm.content)
).then(function (response) {
console.log(response.data);
//You should get your response here
},
function (error) {
console.log("Something went wrong..." + error.status);
});
//您可以创建外部服务并在该服务中调用 api
//在你的控制器中你可以调用该方法
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)