我有角和控制器的$ HTTP功能的數據,但控制器不檢索數據從角發送,在日誌打印
跳過CORS處理:響應已包含 「訪問控制允許來源」頭
我有我的configurate濾波器web.xml
文件頭
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, x-requested-with");
我的角度功能是本
app.controller('LoadCardController', function($scope, $http) {
$scope.executor = function() {
var person = {
name : 'Prueba',
todayDate : 1469679969827
};
console.log("DATA=> ", data);
$http({
method : 'POST',
url : 'http://localhost/myWeb/addPerson',
data : person,
headers : {
'Content-Type' : 'application/json'
}
}).then(function successCallback(response) {
console.log("success");
console.log(response);
}, function errorCallback(response) {
console.log("error");
console.log(response);
});
}
});
和我的控制器是這樣的......
@ResponseBody
@RequestMapping(path = "/addPerson", method = RequestMethod.POST)
public Person addPerson(final Person person) throws CustomException {
person.setAge("18");
person.setBithDay("15");
LOGGER.trace("Add person with data {}", person);
return person;
}
});
}
進來控制器時,人數據爲空,對於名稱和屬性todayDate,由發我角。
我現在控制器是非常簡單的,因爲只有回到同一個人OBJET
我不認爲這與它有什麼關係正如你所說,作爲Spring控制器的CORS能夠接收請求。您是否需要爲所有主機啓用CORS? – Matt