当前位置:网站首页>通俗讲跨域
通俗讲跨域
2022-06-25 15:32:00 【竹林小虾】
前端开发前后端分离的项目,一定会经常遇到跨域(Cross-Origin)的问题,为什么会有跨域?如何解决跨域呢?以及最常见的方法有哪些呢?
what
跨域的全称是跨域资源共享
场景:当你请求的接口地址和现在前端文件服务所在的域(请求的协议,ip和端口)不同的时候,就会报错,如下图
why
跨域问题的产生其实是浏览器的同源策略造成的,同源策略是浏览器的保护机制,只允许网页请求同一域名下的服务。
同源策略的要求是3同:协议,域名和端口都要保持一致
how
【配置后端】CORS
浏览器是否启用跨域保护机制根据后端配置来响应的,所以服务器端需要做一个允许跨域的配置即可
如何配置:
修改接口的响应头:Access-Control-Allow-Origin,值为*,,浏览器判断通过就会允许跨域
【配置中间服务器】反向代理
意思是用一个代理服务器来代理真正的服务端发送请求
【配置中间服务器】正向代理
意思是用一个代理服务器来代理客户端发送请求,一般用浏览器做代理服务器,这个直接在webpack里面配置
JSONP【不推荐】
其实是通过script标签的特性(无跨域限制)来实现跨域的,也需要服务器端配合,且只能用get方法, 有安全隐患,不推荐
边栏推荐
- Highly concurrent optimized Lua + openresty+redis +mysql (multi-level cache implementation) + current limit +canal synchronization solution
- Using reentrantlock and synchronized to implement blocking queue
- Detailed summary of reasons why alertmanager fails to send alarm messages at specified intervals / irregularly
- Stack and queue
- Start using markdown
- Postman usage notes, interface framework notes
- 剑指 Offer 09. 用两个栈实现队列
- 程序员 VS 黑客的思维 | 每日趣闻
- [paper notes] semi supervised object detection (ssod)
- 到底要不要去外包公司?这篇带你全面了解外包那些坑!
猜你喜欢

Single user mode

Several relationships of UML
![[paper notes] contextual transformer networks for visual recognition](/img/e4/45185983e28664564bbf79023ccbf6.jpg)
[paper notes] contextual transformer networks for visual recognition

semget No space left on device

Using R language in jupyter notebook

System Verilog - thread

Download and installation tutorial of consumer

MySQL field truncation principle and source code analysis

JSON module dictionary and string conversion

Globally unique key generation strategy - implementation principle of the sender
随机推荐
在打新债开户证券安全吗,需要什么准备
About?: Notes for
Dynamic memory allocation
About%*s and%* s
通过客户经理的开户链接开股票账户安全吗?
JVM memory region details
[paper notes] street view change detection with deconvolutional networks
If a thread overflows heap memory or stack memory, will other threads continue to work
Source code analysis of nine routing strategies for distributed task scheduling platform XXL job
2.18 codeforces supplement
Es data synchronization mode
GDB debugging
Ten routing strategies for distributed task scheduling platform XXL job
Breakpad usage and DMP analysis
Error com mysql. cj. jdbc. exceptions. Communicationsexception: solutions to communications link failure
(2) Relational database
MySQL transaction characteristics and implementation principle
Errno perrno and strerrno
Software packaging and deployment
解决Visio和office365安装兼容问题