当前位置:网站首页>Cross domain and CORS
Cross domain and CORS
2022-07-19 14:58:00 【Leisurely summer】
1、 Cross domain
Cross domain , In essence, it is a kind of protection processing of browser . If cross domain , When the server returns the result, it will be intercepted by the browser ( Be careful : At this time, the request can be initiated normally , It's just that the browser intercepted it ), The content that caused the response is not available . Generate cross domain
There are several cases :
| Current page URL | The requested page URL | Cross domain or not | reason |
| http://www.lagou.com/ | http://www.lagou.com/index.html | no | Homology ( agreement , domain name , Same port number ) |
| http://www.lagou.com/ | https://www.lagou.com/index.html | Cross domain | Different agreements (http/https) |
| http://www.lagou.com/ | http://www.baidu.com/ | Cross domain | The main domain name is different (lagou/baidu) |
| http://www.lagou.com/ | http://kaiwu.lagou.com/ | Cross domain | Different subdomains (www/kaiwu) |
| http://www.lagou.com:8080 | http://www.lagou.com:8090 | Cross domain | Port number is different (8080/8090) |
2、 To solve the cross domain
2.1、JSONP
The browser allows some with src The label of the property is cross domain , That is, on some labels src Write on attribute url The address will not cause cross domain problems
2.2、CORS To solve the cross domain
CORS It's a W3C standard , The full name is " Cross-domain resource sharing "(Cross-origin resource sharing).CORS Requires both browser and server support . at present , All browsers support this feature ,IE The browser cannot be lower than IE10. Before the browser makes a real request , Will launch a OPTIONS Type of pre inspection request , Used to request whether the server allows cross domain , Only with permission will the request be initiated
3、 be based on Spring Security Of CORS Support
3.1、 Declare cross domain configuration source
/**
* Cross domain information configuration source
*/
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
// Allow cross domain sites
corsConfiguration.addAllowedOrigin("*");
// Allow cross domain http Method
corsConfiguration.addAllowedMethod("*");
// Allow cross domain request headers
corsConfiguration.addAllowedHeader("*");
// It is allowed to carry vouchers
corsConfiguration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
// For all url All in force
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
return urlBasedCorsConfigurationSource;
}3.2、 Turn on cross domain support
// Allow cross-domain
http.cors().configurationSource(corsConfigurationSource());3.3、 Front end cross domain test code
function toCors() {
$.ajax({
// By default , Standard cross domain requests are not sent cookie Of
xhrFields: {
withCredentials: true
},
url: "http://localhost:8090/user/1", // according to ID Query the user
success: function (data) {
alert(" The request is successful ." + data)
}
});边栏推荐
- 滑动窗口最大值问题
- 3U VPX cooling conduction high performance srio/ Ethernet data exchange board
- MySQL storage functions and triggers
- 国科大.深度学习.期末复习知识点总结笔记
- Encrypt Ogg users
- Explain C language dynamic memory management in detail
- LabVIEW uses multithreading. Will the program run faster
- ospf-LSA
- Deployment principle
- Classes abstraites et dérivées
猜你喜欢

Domestic fpga/dsp/zynq Chip & board scheme

BigScience 开源 Bloom 的自然语言处理模型

UCAS. Deep learning Final examination questions and brief thinking analysis

MySQL CPU usage is soaring. How to locate who is occupying it

csrf防护机制

国科大.深度学习.期末复习知识点总结笔记

Wechat applet -- wxss template style

滑動窗口最大值問題

The bill module of freeswitch

Alibaba微服务组件Nacos注册中心
随机推荐
【萌新解题】四数之和
Data consistency between redis and MySQL
Read the paper: temporary graph networks for deep learning on dynamic graphs
[Luogu p3220] and not (construction) (digit DP) (inference)
Code Runner for VS Code,下载量突破 4000 万!支持超过50种语言
Istio XDS配置生成实现
Comparison of two virtual machines
Authing practice | unified management solution for manufacturing identity authentication
ospf-LSA
实习是步入社会的一道坎
Mvcc multi version concurrency control
2021 national vocational college skills competition network construction and application events
CompositionAPI 组件开发范式
Oserror: sndfile library not found solution
Abstract classes and derived classes
滑动窗口最大值问题
session管理
Explain C language dynamic memory management in detail
最大堆与堆排序和优先队列
UCAS. Deep learning Final examination questions and brief thinking analysis