当前位置:网站首页>Common cross domain problems
Common cross domain problems
2022-07-24 04:32:00 【A little every day~】

What is cross-domain ?
Cross domain means that the browser cannot execute scripts of other websites , It can be said that it is closely related to the homology strategy of the browser , It's a strategy for browsers . Homology means agreement , domain name , port all To maintain Agreement
example : http://www.a.com :8080 /stu
agreement domain name port route
Solution :
- JSONP( Rarely used )
JSONP be based on <script> label (<script scr = " 【url+callback( Callback function name )】")></script> Conduct get Request cross domain address , To load data , Make it free from cross domain restrictions , But it can only support GET request , No other request can support .
<script src="http://aaa.com/text?callback=callbackFunction"></script>
// To the server aaa.com Request , The query string for this request has a callback Parameters , Used to specify the name of the callback function
// Process the data returned by the callback function from the server
<script>
function callbackFunction(res){
// Process the data obtained
console.log(res.data)
}
</script>- nginx Reverse proxy ( The most simple ) Equivalent to conversion station
【 proxy server 】
It just needs to be modified nginx Configuration of To solve cross domain problems , Support for all browsers , Support session, You don't need to change any code , It does not affect server performance .
- Cros( common )
stay Springboot Configuration files in the project CorsConfig.java, After restart, cross domain access can be realized , No need for front end Then configure cross domain .
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration
public class CorsConfig {
// Maximum effective duration of current cross domain request . Default here 1 God
private static final long MAX_AGE = 24 * 60 * 60;
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 1 Set access source address (* It can be set to allow only http://localhost:8080 visit )
corsConfiguration.addAllowedHeader("*"); // 2 Set access source request header
corsConfiguration.addAllowedMethod("*"); // 3 Set access source request method
corsConfiguration.setMaxAge(MAX_AGE);
source.registerCorsConfiguration("/**", corsConfiguration); // 4 Configure cross domain settings for interfaces
return new CorsFilter(source);
}
}边栏推荐
- Excel cell formula - realize Ackerman function calculation
- Design of high frequency small signal resonant amplifier course design Multisim Simulation
- 00cm non, make sure to go online with the business party once in advance, and make everything better
- NFT insider 67: Barcelona Football Club launched its first NFT work, and Dubai launched the national metauniverse strategy
- 链接预测中训练集、验证集以及测试集的划分(以PyG的RandomLinkSplit为例)
- Application scenarios and schemes of common mechanical equipment safety virtual simulation system
- Imitate today's headlines real-time news wechat applet project source code
- Jinglianwen technology provides 3D point cloud image annotation service
- LeetCode 46 全排列
- 1.7.1 right and wrong problem (infix expression)
猜你喜欢

A hospital call system based on C language

What are the 10 live demos showing? It's worth watching again whether you've seen it or not

Codeforces Round #809 (Div. 2) A - D1

Avoid mistakes, common appium related problems and Solutions
![[C language] program environment and preprocessing operation](/img/6c/245c20956a40fa37b780abbbcfcaeb.png)
[C language] program environment and preprocessing operation

Will your NFT disappear? Dfinity provides the best solution for NFT storage

Chapter III query processing of PostgreSQL Guide - Insider exploration

Qt5.14_MinGW/MSVC下实现VS2019面板自由拖拽组合功能

《论文复现》BiDAF代码实现过程(3)模型建立

Chery arizer 8 products are powerful, and "all excellent" is not for nothing
随机推荐
An online accident, I suddenly realized the essence of asynchrony
C语言:冒泡排序法
Good performance and reliability. The parameter that initiates writing IIC co type code and is -4
How to change the direction of this gracefully
C语言经典练习题
IPhone binding 163 mailbox solution
Design of two power dividers and directional couplers for basic experiment of microwave technology
Graduation thesis on enterprise production line improvement [Flexsim simulation example]
Smart people's game improvement: Chapter 3 Lesson 3 example: the secret of prime
C language classic exercises
Share a login interface template of QT implementation
Where is the difficulty in attracting investment in the park? Inventory of difficulties and difficulties in attracting investment in industrial parks
Particle Designer:粒子效果制作器,生成plist文件并在工程中正常使用
How about opening an account for Guotai Junan Securities? Is it safe
Educational Codeforces Round 132 A - D
What are the 10 live demos showing? It's worth watching again whether you've seen it or not
Traversal of binary tree
Teacher qiniu said is the VIP account opened for you safe?
Excel cell formula - realize Ackerman function calculation
What new opportunities exist in the short video local life section?