【发布时间】:2016-01-06 09:23:52
【问题描述】:
我想在 Spring Security 下发送 POST 请求到服务。 如果我使用表单提交(带有隐藏输入) - 它工作正常。 但我不知道,如何使用 $http.post 发送请求。 我的表格:
<form method="POST" type="submit" action="http://localhost:8888/rest/post1" />
<button>345</button>
<input name="${_csrf.parameterName}"
value="${_csrf.token}" />
</form>
它工作。
我保存参数:
<script>
var a = "${_csrf.parameterName}";
var b = "${_csrf.token}";
</script>
我的 ng-click 功能:
$http.post('http://localhost:8888/rest/post1', {"_csrf": b}, {
"headers" :
{ "_csrf" : b }
}).success(function(data) {
console.log("ok");
}).error(function(){
console.log("no");
});
它总是写“不”。
我认为,需要将变量作为 webForm 发送,但是如何在 $http.post 中发送?
提琴手写:Content-Type is 'application/json'; this inspector supports 'x-www-form-urlencoded' only
服务器控制台:
org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
WARNING: Request method 'POST' not supported
请帮帮我!
【问题讨论】:
-
这可能会有所帮助:[stackoverflow.com/questions/18156452/…
-
不,不要帮忙,谢谢
标签: angularjs jsp spring-security csrf