当前位置:网站首页>How to implement cross domain requests
How to implement cross domain requests
2022-07-04 06:02:00 【Daily enlightenment】
Method 1 :
@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig(){
CorsConfiguration configuration = new CorsConfiguration();
// Set properties
// Addresses that allow cross domain requests ,* Express all
configuration.addAllowedOrigin("*");
// Configure cross domain request headers
configuration.addAllowedHeader("*");
// Configure cross domain request methods
configuration.addAllowedMethod("*");
// Indicates whether the same is used for cross domain requests session
configuration.setAllowCredentials(true);
return configuration;
}
@Bean
public CorsFilter corsFilter(){
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**",buildConfig());
return new CorsFilter(source);
}
}
Method 2 :
@CrossOrigin(origins = "*",allowedHeaders = "*",methods = {},allowCredentials = "true")
@RestController
@CrossOrigin(origins = "*",allowedHeaders = "*",methods = {},allowCredentials = "true")
public class TestController {
@RequestMapping("/auth/login")
public String test(){
System.out.println("test");
return "";
}
}边栏推荐
- Yiwen unlocks Huawei's new cloud skills - the whole process of aiot development [device access - ESP end-to-side data collection [mqtt]- real time data analysis] (step-by-step screenshot is more detai
- left_ and_ right_ Net normal version
- Kubernets first meeting
- AWT common components, FileDialog file selection box
- Input displays the currently selected picture
- Learning multi-level structural information for small organ segmentation
- [Chongqing Guangdong education] electronic circuit homework question bank of RTVU secondary school
- Nexus 6p从8.0降级6.0+root
- Invalid revision: 3.18.1-g262b901-dirty
- AWT介绍
猜你喜欢
随机推荐
冲击继电器JC-7/11/DC110V
input显示当前选择的图片
19. Framebuffer application programming
Leakage detection relay jy82-2p
QT get random color value and set label background color code
Arc135 a (time complexity analysis)
Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
复合非线性反馈控制(二)
left_ and_ right_ Net normal version
Wechat applet +php realizes authorized login
Arc135 C (the proof is not very clear)
Google Chrome browser will support the function of selecting text translation
Detailed explanation of common APIs for component and container containers: frame, panel, scrollpane
How to solve the component conflicts caused by scrollbars in GridView
Upper computer software development - log information is stored in the database based on log4net
How to avoid JVM memory leakage?
C语言练习题(递归)
Thinkphp6.0 middleware with limited access frequency think throttle
如何展开Collapse 的所有折叠面板
Understanding of cross domain and how to solve cross domain problems









