美文网首页
响应头设置跨域和Spring注解跨域

响应头设置跨域和Spring注解跨域

作者: Ethan_Walker | 来源:发表于2017-08-29 11:20 被阅读376次

CORS跨域原理详解
Spring解决跨域

  1. 响应头设置跨域
    @RequestMapping(value = "/ajax")
    public @ResponseBody
    Customer ajax(Integer id, HttpServletResponse response) {
        Customer customer = customerService.queryCustomerById(id);
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization");
        response.setHeader("Access-Control-Allow-Credentials", "true");
        return customer;
    }

  1. Spring注解跨域
    @CrossOrigin 可添加到方法上,也可添加到类上
    // orgins=''http://localhost:63343"表示允许域名为
 http://localhost:63343 访问该方法
  // origins="*", 表示允许所有其他的网站访问该方法
    @CrossOrigin(origins = "http://localhost:63343")
    @RequestMapping(value = "/ajax")
    public @ResponseBody
    Customer ajax(Integer id, HttpServletResponse response) {
        Customer customer = customerService.queryCustomerById(id);
        return customer;
    }

相关文章

  • 响应头设置跨域和Spring注解跨域

    CORS跨域原理详解Spring解决跨域 响应头设置跨域 Spring注解跨域@CrossOrigin 可添加到方...

  • 2018-12-11

    spring security 的跨域问题 spring security跨域设置 在spring-sercuri...

  • Node 跨域 Access to XMLHttpRequest

    如果跨域用到了put,patch方法,要在响应头设置

  • 解决跨域问题的5种状况

    跨域主要涉及4个响应头: Access-Control-Allow-Origin用于设置允许跨域请求源地址 (预检...

  • 2019-04-01

    Spring Boot轻松跨域:Spring Boot中采用注解轻松实现跨域的一个基础例子 1.项目结构,conf...

  • 跨域响应头设置

    项目中大家可能不是一个网段。除了给chrome添加--disable-web-security外,后端的相应头应该...

  • 我和跨域的狗皮膏药故事

    跨域 谈谈跨域之前, 我们先谈谈这几个响应头. Access-Control-Allow-Credentials ...

  • 跨域的解决方案

    1通过cors设置cors头解决跨域,也可以针对一个接口使用cors()中间件解决跨域 2通过设置响应头访问允许控...

  • C# Web直接上传视频或者文件到OSS

    代码 解决本地调试跨域问题 设置跨域规则:找到OSS存储——Bucket列表——基础设置——跨域访问——设置 暴露...

  • Nodejs 设置跨域

    设置允许所有域名跨域: 设置允许指定域名“http://www.tefang.cn”跨域: 设置允许多个域名跨域:...

网友评论

      本文标题:响应头设置跨域和Spring注解跨域

      本文链接:https://www.haomeiwen.com/subject/tgcodxtx.html