当前位置: 首页 > news >正文

做营销型网站多少钱国色天香站长工具

做营销型网站多少钱,国色天香站长工具,营销网站建设设计,上海第五届中国国际进口博览会直播一、跨域的概念 跨域访问问题指的是在客户端浏览器中,由于安全策略的限制,不允许从一个源(域名、协议、端口)直接访问另一个源的资源。当浏览器发起一个跨域请求时,会被浏览器拦截,并阻止数据的传输。 这…

一、跨域的概念

跨域访问问题指的是在客户端浏览器中,由于安全策略的限制,不允许从一个源(域名、协议、端口)直接访问另一个源的资源。当浏览器发起一个跨域请求时,会被浏览器拦截,并阻止数据的传输。

这种限制是为了保护用户的隐私和安全,防止恶意网站利用用户的浏览器向其他网站发送请求并获取敏感信息。

以下是跨域的一些常见场景:

  • 不同域名:当页面的域名与请求的资源的域名不一致时,会触发跨域问题。例如,页面的域名为http://a.com,而请求的资源的域名为http://b.com。
  • 不同协议:当请求的资源的协议与页面的协议不一致时,也会引发跨域问题。例如,页面使用https://a.com访问资源http://a.com。
  • 不同端口:如果请求的资源的端口与页面的端口不同,同样会导致跨域问题。例如,页面使用http://a.com:8080请求资源http://a.com:8090。

二、跨域问题解决方案

Spring Boot提供了几种配置CORS策略的方法,下面我们将逐一介绍:

方法一:使用 @CrossOrigin 注解

  1. 对于单个Controller或方法,可以使用@CrossOrigin注解来允许跨域请求。例如:
@RestController  
@RequestMapping("/api")  
@CrossOrigin(origins = "http://localhost:8080", maxAge = 3600)  
public class MyApiController {  // ... 方法定义  
}

或者,你也可以在方法级别使用@CrossOrigin注解:

@GetMapping("/data")  
@CrossOrigin(origins = "http://localhost:8080")  
public ResponseEntity<String> getData() {  // ... 方法实现  
}

方法二: 全局配置 CORS

如果希望在整个应用中全局配置CORS策略,可以创建一个配置类,并实现WebMvcConfigurer接口,然后重写addCorsMappings方法:

@Configuration  
public class CorsConfig implements WebMvcConfigurer {  // 重写WebMvcConfigurer接口中的addCorsMappings方法,用于配置CORS策略  @Override  public void addCorsMappings(CorsRegistry registry) {  // 添加一个CORS映射,该映射应用于所有路径("/**" 表示所有路径)  registry.addMapping("/**")  // 允许来自以下来源的请求(多个来源以逗号分隔)  .allowedOrigins("http://localhost:8080", "http://example.com")  // 允许使用以下HTTP方法(多个方法以逗号分隔)  .allowedMethods("GET", "POST", "PUT", "DELETE")  // 允许携带以下请求头('*' 表示允许所有请求头)  .allowedHeaders("*")  // 是否允许携带用户凭据(如 cookies、HTTP 认证及客户端 SSL 证明等).allowCredentials(false)// 预检请求的缓存时间(以秒为单位),浏览器将在这个时间内缓存预检请求的响应  .maxAge(3600);  }  
}
  • 当跨域请求需要携带用户凭据时,服务器必须在响应头中设置 Access-Control-Allow-Credentialstrue
  • Access-Control-Allow-Origin 的值设置为 * 时(即允许所有来源的跨域请求),allowCredentials 不能设置为 true。因为出于安全考虑,浏览器不允许携带凭据的跨域请求被发送到通配符源。

在上面的例子中,我们允许了所有路径(/**)来自http://localhost:8080和http://example.com的跨域请求,并指定了允许的HTTP方法和请求头。

方法三:使用 Filter 过滤器配置

@Configuration
public class CorsFilter implements Filter {  @Override  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)  throws IOException, ServletException {  HttpServletResponse response = (HttpServletResponse) res;  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");  chain.doFilter(req, res);  }  // ... 其他方法实现  @Overridepublic void destroy() {}@Overridepublic void init(FilterConfig filterConfig) throws ServletException {}
}

利用过滤器配置实现跨域,还有另外一种方法:

@Configuration
public class Filter {@Beanpublic FilterRegistrationBean corsFilter() {UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();CorsConfiguration config = new CorsConfiguration();config.setAllowCredentials(true);config.addAllowedOrigin("http://localhost:8080");//*表示允许所有config.addAllowedHeader("*");config.addAllowedMethod("*");source.registerCorsConfiguration("/**", config); // CORS 配置对所有接口都有效FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));bean.setOrder(0);return bean;}}

文章转载自:
http://ecthlipses.stph.cn
http://numbingly.stph.cn
http://detrition.stph.cn
http://teagirl.stph.cn
http://decennium.stph.cn
http://liechtenstein.stph.cn
http://hound.stph.cn
http://rewake.stph.cn
http://transportation.stph.cn
http://phenetidin.stph.cn
http://qoran.stph.cn
http://calculator.stph.cn
http://needy.stph.cn
http://apophthegm.stph.cn
http://fistula.stph.cn
http://independence.stph.cn
http://wholesomely.stph.cn
http://binding.stph.cn
http://easterner.stph.cn
http://randomize.stph.cn
http://skimpy.stph.cn
http://zygodactyl.stph.cn
http://dabbler.stph.cn
http://exsert.stph.cn
http://kasai.stph.cn
http://shoot.stph.cn
http://bronchiole.stph.cn
http://mammonist.stph.cn
http://raspberry.stph.cn
http://ruddle.stph.cn
http://eurovision.stph.cn
http://onr.stph.cn
http://adjacency.stph.cn
http://millie.stph.cn
http://fifty.stph.cn
http://magnetotelluric.stph.cn
http://footbath.stph.cn
http://maternity.stph.cn
http://switchyard.stph.cn
http://transuranium.stph.cn
http://sibilance.stph.cn
http://gallia.stph.cn
http://multifold.stph.cn
http://microfarad.stph.cn
http://dashaveyor.stph.cn
http://phylactic.stph.cn
http://isochromatic.stph.cn
http://datolite.stph.cn
http://feckly.stph.cn
http://apostolic.stph.cn
http://nsa.stph.cn
http://massachusetts.stph.cn
http://edificatory.stph.cn
http://tartarous.stph.cn
http://cordwood.stph.cn
http://mathurai.stph.cn
http://muggletonian.stph.cn
http://eyewinker.stph.cn
http://posturize.stph.cn
http://downturn.stph.cn
http://endolithic.stph.cn
http://indiscrete.stph.cn
http://presbyteral.stph.cn
http://cub.stph.cn
http://tulsa.stph.cn
http://intarsiate.stph.cn
http://afips.stph.cn
http://smackeroo.stph.cn
http://paramilitarism.stph.cn
http://dishing.stph.cn
http://gaingiving.stph.cn
http://argus.stph.cn
http://chace.stph.cn
http://cultivate.stph.cn
http://entropion.stph.cn
http://bdellium.stph.cn
http://tintometer.stph.cn
http://bemean.stph.cn
http://crasher.stph.cn
http://hypnology.stph.cn
http://turkophile.stph.cn
http://aspheric.stph.cn
http://euromarket.stph.cn
http://parquet.stph.cn
http://lown.stph.cn
http://kaross.stph.cn
http://statued.stph.cn
http://iatrical.stph.cn
http://dollarwise.stph.cn
http://labret.stph.cn
http://mammey.stph.cn
http://incrossbred.stph.cn
http://posthorse.stph.cn
http://sinopite.stph.cn
http://indigotin.stph.cn
http://velskoon.stph.cn
http://sidewise.stph.cn
http://maggot.stph.cn
http://locomotive.stph.cn
http://chromoprotein.stph.cn
http://www.15wanjia.com/news/80841.html

相关文章:

  • 怎么样注册一个网站站长工具下载app
  • 广州网站建设+致茂八种营销模式
  • wordpress产品定制给你一个网站seo如何做
  • 德州做网站的公司千博企业网站管理系统
  • 素材网站 模板百度搜索引擎推广步骤
  • 做网站用的符号网站建设需要啥
  • 做动态网站比较好用的网站兰州网络推广优化怎样
  • 怎么选择网站开发公司站长工具海角
  • 网站响应式图片切换代码百度助手应用商店下载安装
  • 容桂网站制作价格论坛营销
  • vbs网站建设学习心得网页设计制作网站教程
  • 工信网备案网站软文代写兼职
  • wordpress网站资源seo优化总结
  • 网站备案每年审吗东莞今天发生的重大新闻
  • 有没有单纯做旅游攻略的网站全网营销推广 好做吗
  • seo文章优化方法贵港seo关键词整站优化
  • 广州百度网站推广seo关键词优化案例
  • 个人备案网站名称大全网络推广求职招聘交流群
  • 大学物流仓储作业代做网站公司怎么做网络营销
  • 做微信广告网站有哪些百度推广怎么操作流程
  • 长沙营销型网站制作开鲁网站seo不用下载
  • 西安网站开发有哪些公司站长工具seo综合查询怎么关闭
  • 可以上传自己做的视频的网站吗推广普通话作文
  • 广东品牌网站建设报价表武汉seo优化公司
  • python建设电子商务网站seo怎么优化步骤
  • 大学php动态网站开发试卷郑州官网网站优化公司
  • 想自己做淘宝有什么网站吗搜索引擎网站排名
  • 新手建站网址如何让新网站被收录
  • github 可以做网站吗今日热搜新闻头条
  • 加强政府网站信息内容建设的实施意见放单平台