【纠错】前后端跨域失败:No 'Access-Control-Allow-Origin' header is present on the requested resource

MyBatis+vue+Springmvc框架

  • 跨域请求失败错误:
    【纠错】前后端跨域失败:No 'Access-Control-Allow-Origin' header is present on the requested resource
  • 此处为改写后端,增加配置文件:package_config:CroConfig.java
package com.wch.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CrosConfig implements WebMvcConfigurer {
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
上一篇:hxpCTF 2021 revvm Writeup


下一篇:“百度杯”CTF比赛 九月场_123_WriteUp