Access to XMLHttpRequest at ‘xxxxx‘ from origin :xxxxx has been ssss,跨域访问

简介: Access to XMLHttpRequest at ‘xxxxx‘ from origin :xxxxx has been ssss,跨域访问

1、这个问题怎样解决,这里我们后端端口是9000端口,前端是8080端口

1.1 如何解决跨域访问的问题:在util文件夹下创建WebConfig类,通过这个类来解决跨域访问的配置

2、添加@Configuration来生命一个全局的配置类,配置好全局都生效

3、继承相关的类,使他能够进行跨域访问配置

4、alt + insert 重写方法,

5、addCorsMapping方法

6、addMapping什么路径可以进行访问

7、allowOrigin是对那个端口进行跨域访问

8、allowedMethods运行什么请求

9、允不允许凭证

10、配置完就可以获的信息了

11、相关配置类:

package com.example.ymzting_dm_web.util;
 
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8080")
                .allowedMethods("GET","POST","PUT","OPTIONS","DELETE")
                .allowCredentials(true)
                .maxAge(3600);
    }
}
相关文章
|
缓存 对象存储 数据安全/隐私保护
阿里云OSS图片访问出现跨域:Access to image at from origin has been blocked by CORS policy
阿里云OSS图片访问出现跨域:Access to image at from origin has been blocked by CORS policy
2926 0
阿里云OSS图片访问出现跨域:Access to image at from origin has been blocked by CORS policy
|
JSON 前端开发 API
【跨域报错解决方案】Access to XMLHttpRequest at ‘http://xxx.com/xxx‘ from origin ‘null‘ has been blocked by
【跨域报错解决方案】Access to XMLHttpRequest at ‘http://xxx.com/xxx‘ from origin ‘null‘ has been blocked by
3700 0
|
6月前
|
前端开发 Java
前后端分离的跨域问题解决:No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
本文介绍了解决前后端分离项目中跨域问题的方法,包括添加`CorsConfig`配置类和重写`WebMvcConfigurer`接口的`addCorsMappings`方法,允许前端请求访问后端资源,并提供了具体的代码示例。
前后端分离的跨域问题解决:No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
|
7月前
|
Kubernetes 数据安全/隐私保护 容器
【Azure APIM】APIM Self-Hosted网关中,添加网关日志以记录请求头信息(Request Header / Response Header)
【Azure APIM】APIM Self-Hosted网关中,添加网关日志以记录请求头信息(Request Header / Response Header)
|
8月前
|
缓存 对象存储 数据安全/隐私保护
阿里云OSS, 跨域请求, No ‘Access-Control-Allow-Origin‘
阿里云OSS, 跨域请求, No ‘Access-Control-Allow-Origin‘
916 0
|
9月前
|
Web App开发 前端开发 安全
设置跨域规则后调用OSS时仍然报“No ‘Access-Control-Allow-Origin‘”的错误
设置跨域规则后调用OSS时仍然报“No ‘Access-Control-Allow-Origin‘”的错误
206 0
|
缓存 安全 搜索推荐
Cors跨域(三):Access-Control-Allow-Origin多域名?
Cors跨域(三):Access-Control-Allow-Origin多域名?
Cors跨域(三):Access-Control-Allow-Origin多域名?
|
API
百度API调用JSONP解决跨越问题 been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ header
百度API调用JSONP解决跨越问题 been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ header
285 0
|
前端开发 JavaScript
ajax请求的重定向处理--Request header field x-requested-with is not allowed by Access-Control-Allow-Header
ajax请求的重定向处理--Request header field x-requested-with is not allowed by Access-Control-Allow-Header
590 0
|
Web App开发 存储 安全
新版本Chrome同源策略、跨域问题处理No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
新版本Chrome同源策略、跨域问题处理No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
902 0