Could not verify the provided CSRF token because your session was not found in spring security

前端 未结 7 2129
甜味超标
甜味超标 2020-12-15 03:09

I am using spring security along with java config

@Override
protected void configure(HttpSecurity http) throws Exception { 
    http
    .authorizeRequests()         


        
7条回答
  •  一生所求
    2020-12-15 03:44

    I get this error message (HTTP Status 403 - Could not verify the provided CSRF token because your session was not found.) when I do a JS fetch AJAX call without using the credentials: "same-origin" option.

    Wrong way

    fetch(url)
    .then(function (response) { return response.json(); })
    .then(function (data) { console.log(data); })
    

    Correct way

    fetch(url, {
        credentials: "same-origin"
    })
    .then(function (response) { return response.json(); })
    .then(function (data) { console.log(data); })
    

提交回复
热议问题