springboot +security post请求报403

使用springboot 2 + spring security4 搭建登陆框架。

login.html页面通过form表单post方法进行登陆提交, 系统报403错误, 查询baidu无果,在google上一篇文章提到由于请求没有加csrf的tonken。

于是,按照spring 的参考手册上的方法(thymeleaf语法),添加上token, 问题解决,见如下图:

<form action="/login" method="post">
    <table>
        <tr>
            <td>用户名:</td>
            <td><input type="text" name="username"></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input type="password" name="password"></td>
        </tr>
        <tr>
            <td colspan="2"><button type="submit">登录</button></td>
        </tr>
    </table>
    <input type="hidden"
           th:name="${_csrf.parameterName}"
           th:value="${_csrf.token}"/>
</form>

猜你喜欢

转载自blog.csdn.net/tony820418/article/details/81506671