【发布时间】:2017-10-15 07:52:48
【问题描述】:
当向我的服务发送 http.post 请求时,我最初会发送一个 Option 请求(根据 Cors 的要求)。
但是我意识到我的 OPTIONS(飞行前)请求在其响应中没有返回 response.data,但我的 POST 请求是。这带来了一个问题,因为我需要从 POST 响应中访问 response.data...
Angular 是否允许我们以某种方式丢弃 http.post 调用中的 OPTIONS 响应?
$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 = "";
});
【问题讨论】:
-
你能澄清你的问题吗?您声明:“但我的 POST 请求是……我需要从 POST 响应中访问 response.data。” - 这没有意义。
-
问题和我描述的完全一样。我收到两个响应,一个用于 OPTIONS 请求,另一个用于 POST 请求。 OPTIONS 请求似乎在 POST 之前返回,即使我只是向服务发送 POST 请求。如何丢弃 OPTIONS 响应?
-
@geostocker 你找到解决方案了吗?
标签: javascript angularjs rest cors