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
1912 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
2490 0
|
1天前
|
缓存 对象存储 数据安全/隐私保护
阿里云OSS, 跨域请求, No ‘Access-Control-Allow-Origin‘
阿里云OSS, 跨域请求, No ‘Access-Control-Allow-Origin‘
6 0
|
23天前
|
Web App开发 前端开发 安全
设置跨域规则后调用OSS时仍然报“No ‘Access-Control-Allow-Origin‘”的错误
设置跨域规则后调用OSS时仍然报“No ‘Access-Control-Allow-Origin‘”的错误
31 0
|
开发工具 数据安全/隐私保护 git
Git报错:remote: HTTP Basic: Access denied的解决方法
Git报错:remote: HTTP Basic: Access denied的解决方法
1342 0
Git报错:remote: HTTP Basic: Access denied的解决方法
|
API 开发工具 git
解决 `remote: You must use a personal access token with 'api' scope for Git over HTTP.`
`git clone` 报错,解决 `remote: You must use a personal access token with 'api' scope for Git over HTTP.`
316 0
解决 `remote: You must use a personal access token with 'api' scope for Git over HTTP.`
|
12月前
|
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
174 0
|
缓存 安全 搜索推荐
Cors跨域(三):Access-Control-Allow-Origin多域名?
Cors跨域(三):Access-Control-Allow-Origin多域名?
Cors跨域(三):Access-Control-Allow-Origin多域名?
|
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.
616 0
|
开发工具 数据安全/隐私保护 git
git 报错:remote: HTTP Basic: Access denied
git 报错:remote: HTTP Basic: Access denied
127 0
git 报错:remote: HTTP Basic: Access denied