当前位置:网站首页>Cross-domain network resource file download
Cross-domain network resource file download
2022-08-01 10:02:00 【ten nine eight seven】
Question
Under normal circumstances, it is impossible to send cross-domain requests to download files.Take downloading Yuque as an example: you can see that if you directly access the download address, a cross-domain error will be reported
Resolve
At this time, we can forward the request through the nginx configuration proxy to complete the download:
location ^~ /yuque/ {proxy_pass https://app.nlark.com/yuque-desktop/;}Description: When we send a request like
/yuque/locally, nginx will forward the request (Note:/must be added at the end, otherwise it is a proxy request, addThen the forwarding request), will forward/yuque/to the followinghttps://app.nlark.com/yuque-desktop/
Then we rewrite the download request:
var xhr = new XMLHttpRequest();xhr.open("GET", "/yuque/1.1.4/Yuque-1.1.4.exe", true);xhr.send();This time, we will not directly access the Yuque download address, but visit our local address, and then nginx will forward our request and forward
/yuque/tohttps://app.nlark.com/yuque-desktop/, then the forwarded request becomeshttps://app.nlark.com/yuque-desktop/1.1.4/Yuque-1.1.4.exe.Since we do not directly request the download address, but the local address of the request, and forward the request through the proxy of nginx, there is naturally no cross-domain problem (if you don't understand, you can read the article I wrote about nginx reverse proxy before)
Afterword
Because nginx does not pass reverse proxy but forward proxy requests, in this process, the resource passes through the nginx server once, and then nginx sends the resource to the requester, so this process needs to consume the location of nginxserver traffic.
边栏推荐
- Dataset之mpg:mpg数据集的简介、下载、使用方法之详细攻略
- 数仓分层简介(实时数仓架构)
- Introduction and application of pointers
- Enterprise WeChat group: robot timing reminder function database configuration
- WPF 截图控件之绘制箭头(五)「仿微信」
- MTK6225-紧急电话
- notes....
- pve 删除虚拟机「建议收藏」
- URL.createObjectURL、URL.revokeObjectURL、Uint8Array、Blob使用详解
- 还在纠结报表工具的选型么?来看看这个
猜你喜欢
随机推荐
报告:想学AI的学生数量已涨200%,老师都不够用了
Comprehensive experiment BGP
YOLOv7-Pose尝鲜,基于YOLOv7的关键点模型测评
基于ModelArts的物体检测YOLOv3实践【玩转华为云】
ClickHouse入门介绍与其特性
CTO强烈禁止使用Calendar,那用啥?
Shell: Conditional test action
记一次 .NET 某智慧物流WCS系统CPU爆高分析
7/31 训练日志
RK3399平台开发系列讲解(内核入门篇)1.52、printk函数分析 - 其函数调用时候会关闭中断
广域铭岛入选2022年重庆市数字经济产业发展试点示范项目名单
Node's traditional and advanced practices for formatting time (moment)
昇思大模型体验平台初体验——以小模型LeNet为例
杨辉三角(c语言实现)
MTK6225-紧急电话
InputStream转成String
50.【Application of dynamic two-dimensional array】
SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
自定义类型——枚举、联合
微服务:事务管理









