【问题标题】:SPRING - what is the meaning of ORIGIN in CORSSPRING - CORS中ORIGIN是什么意思
【发布时间】:2018-11-02 18:26:21
【问题描述】:

不知道web开发中ORIGIN是什么意思,spring框架中是什么意思,下面this example的origin属性是什么意思:

@CrossOrigin(origins = "http://domain2.com", maxAge = 3600)
@RestController
@RequestMapping("/account")
public class AccountController {

    @GetMapping("/{id}")
    public Account retrieve(@PathVariable Long id) {
    // ...
    }

    @DeleteMapping("/{id}")
    public void remove(@PathVariable Long id) {
        // ...
    }
 }

http://domain2.com是什么意思,CORS在服务器端和客户端的机制是什么(我不明白链接中银行账户的例子) .

提前谢谢你。

【问题讨论】:

  • 这与 Spring 无关。基本上,您将要访问 Spring 后端的所有域都放入 origins 数组。如果您不想麻烦,只需将其设置为 * 以允许所有来源。

标签: java spring browser cors


【解决方案1】:

@CrossOrigin 不带参数意味着您的控制器将接受所有请求。 @CrossOrigin(origins = "http://domain2.com", maxAge = 3600) 表示它只接受来自此 url 的请求:"http://domain2.com"

例如,如果您的客户端在服务器“hhtp://localhost:8080”上,并且他向您的服务发送请求 GET /account/5 您的服务会拒绝。

【讨论】:

    猜你喜欢
    • 2011-07-13
    • 2016-07-12
    • 2014-06-08
    • 2021-08-06
    • 2013-03-04
    • 2015-03-18
    • 2018-02-06
    • 1970-01-01
    • 2011-08-12
    相关资源
    最近更新 更多