首页 > 解决方案 > 从弹簧控制器获取数据

问题描述

我需要从 spring 控制器获取数据,但服务器总是返回 403 Forbidden。Spring 服务器使用 LDAP 身份验证。我添加了凭据: 'include',但没有任何改变。

这是我的 download.js

fetch("/test", {
        credentials: 'include',
        method: "POST",
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Cache': 'no-cache'
        }
    })
    .then((response)=>{
        alert(response);
        return response.json();
    })
    .then((data)=>{
        console.log(data);
        alert(data);
    });

这是我的控制器

@RestController
public class TestController {

    @Autowired
    private CalcVersionsService calcVersionsService;

    @PostMapping("/test")
    @ResponseBody
    public Set<CalcVersion> test(){

        return calcVersionsService.findAll();
    }
}

结果图片

如何向服务器发出授权请求?

标签: javascriptspringspring-bootldapfetch

解决方案


推荐阅读