当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
VS“无法查找或打开PDB文件”是怎么回事?如何解决
opencv创建窗口—cv.namedWindow()
Google Earth Engine APP——15行代码搞定一个inspector高程监测APP
In the background of the GBase 8c database, what command is used to perform the master-slave switchover operation for the gtm and dn nodes
跨域网络资源文件下载
解决new Thread().Start导致高并发CPU 100%的问题
笔记。。。。
还在纠结报表工具的选型么?来看看这个
浏览器快捷键大全
常见的API安全缺陷有哪些?
STM32个人笔记-嵌入式C语言优化
如何在IntellJ IDEA中批量修改文件换行符
experiment....
怎么找出电脑隐藏的软件(如何清理电脑隐藏软件)
net stop/start mysql80 access denied
MTK6225-紧急电话
7. SAP ABAP OData 服务如何支持 $orderby (排序)操作
SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
ClickHouse多种安装方式
Comprehensive experiment BGP









