在整合spring boot 和spring security的时候,用AJAX提交数据浏览器返回以下提示:
responseText:
""timestamp":1501832200997,"status":403,"error":"Forbidden","message":"Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.","path":"/record/getWaitReceive"}"
查询发现原因是spring security开启了CSRF防御,提交数据时需要同时将${_CSRF}参数传到后台,故,在ajax data内添加以下:
${_csrf.parameterName} : "${_csrf.token}"
即可。
若是表单提交:则添加:
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>