gpt4 book ai didi

Spring 安全 REST API

转载 作者:行者123 更新时间:2023-12-01 10:48:53 25 4
gpt4 key购买 nike

我将 Spring Security REST Api 与 grails 和 AngularJS 结合使用。我用 postman 尝试了 url 请求,它工作正常。它使用使用过的 x-auth-token 返回结果。但同样我尝试使用 AngularJs,但它没有进一步满足 OPTION 请求。 here it shows that my request is being processed up to OPTION request only. below is the image which shows what I tried in POSTMAN. It gives the results and works fine with x-auth-token.

I have integrated spring security plugin as following. And it is working for "api/login" but further it fails.

在此处的第一张图片中,它显示我的请求正在处理直至 OPTION 请求。在第二张图片中,显示了我在 POSTMAN 中尝试过的内容。它给出了结果并且可以与 x-auth-token 一起正常工作。在第三张图片中,我已经集成了 spring security 插件,如下所示。它正在为“api/login”工作,但它进一步失败了。第 4 张图片显示了 OPTION 请求的详细响应,然后它无法继续。 4th

我写了如下的 grunt connect 方法

connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
proxies: [
{
context: '/crm/api',
host: 'localhost',
port: 8080
}
],
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>'
]
}
},
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'<%= yeoman.app %>'
]
}
},
dist: {
options: {
base: '<%= yeoman.dist %>'
}
}
}

我仍然有同样的错误。

最佳答案

这是一个跨域问题。

您的网页位于 localhost:9000,您的后端位于 localhost:8080。这些在技术上是 2 个不同的域,因此您需要启用跨源请求,或使用代理将请求转发到端口 8080

看起来你正在使用 grunt,所以我建议设置代理。我用 grunt-connect-proxy设置转发到我的后端端口:

connect: {
options: {
port: 9000,
hostname: 'localhost',
livereload: 35729
},
proxies: [
{
context: '/crm/api',
host: 'localhost',
port: 8080
}
]
}

关于 Spring 安全 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22535170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com