Spring Rest Service - Invalid CSRF token when I attempt to login

后端 未结 3 912
Happy的楠姐
Happy的楠姐 2021-01-05 10:31

I have a Spring MVC REST service, with Spring Security (3.2.5.RELEASE) enabled. When I turn on @EnableWebMvcSecurity, a login form is automatically generated for me at http:

3条回答
  •  执念已碎
    2021-01-05 11:32

    (1) Include the CSRF token within all your AJAX requests.

    $(function () {
        var token = $('#logoutform>input').val();
        var header = $('#logoutform>input').attr('name');
        $(document).ajaxSend(function(e, xhr, options) {
            xhr.setRequestHeader('X-CSRF-TOKEN', token);
        });
     });
    

    (2) Simple request .

    
    

提交回复
热议问题