当前位置:网站首页>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.
边栏推荐
猜你喜欢

会议OA(待开会议&所有会议)

报告:想学AI的学生数量已涨200%,老师都不够用了

C language game - minesweeper
![[Software Architecture Mode] The difference between MVVM mode and MVC mode](/img/37/8470ff9267752d4ca26a6b54ec0b50.png)
[Software Architecture Mode] The difference between MVVM mode and MVC mode

AI篮球裁判火了,走步算得特别准,就问哈登慌不慌

WPF 截图控件之绘制箭头(五)「仿微信」

Yang Hui Triangle (C language implementation)

CTO strongly banning the use of the Calendar, that in what?

WTM:ASP.NET Core快速开发利器!

Custom Types - Enums, Unions
随机推荐
将本地项目推送到远程仓库
The soul asks: How does MySQL solve phantom reads?
Analysis of High Availability Solution Based on MySql, Redis, Mq, ES
ASP.NET Core 6框架揭秘实例演示[30]:利用路由开发REST API
笔记。。。。
7/31 训练日志
编码解码(btoa、encodeURIComponent、encodeURI、escape)
C语言程序设计50例(三)(经典收藏)
scrapy爬虫框架的使用
50.【Application of dynamic two-dimensional array】
Shell:条件测试操作
SQL Server database schema and objects related knowledge notes
报告:想学AI的学生数量已涨200%,老师都不够用了
Go-Excelize API source code reading (8) - GroupSheets(sheets []string), UngroupSheets()
C#/VB.NET 将PPT或PPTX转换为图像
【cartographer ros】十: 延时和误差分析
Opencv creates a window - cv.namedWindow()
【软件架构模式】MVVM模式和MVC模式区别
Detailed explanation of JVM runtime data area and JMM memory model
URL.createObjectURL、URL.revokeObjectURL、Uint8Array、Blob使用详解