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

Py之yellowbrick:yellowbrick的简介、安装、使用方法之详细攻略

Comprehensive experiment BGP

《时代》杂志:元宇宙时代将改变世界

Message queue interview latest finishing (2022)

redis

Explain / Desc 执行计划分析

18张图,直观理解神经网络、流形和拓扑

CTO strongly banning the use of the Calendar, that in what?
Get the Token from the revised version of Qubutu Bed

DBPack SQL Tracing 功能及数据加密功能详解
随机推荐
Comprehensive experiment BGP
报告:想学AI的学生数量已涨200%,老师都不够用了
微服务:事务管理
cisco交换机基本配置命令(华为交换机保存命令是什么)
安装GBase 8c数据库的时候,报错显示“Resource,如何解决?
跨域网络资源文件下载
js中如何实现深拷贝?
C语言小游戏——扫雷
Introduction and application of pointers
【Untitled】
notes....
STM32 Personal Notes - Watchdog
开天aPaaS之移动手机号码空号检测【开天aPaaS大作战】
VS“无法查找或打开PDB文件”是怎么回事?如何解决
会议OA(待开会议&所有会议)
三子棋(C语言实现)
DBPack SQL Tracing 功能及数据加密功能详解
CTFshow,命令执行:web34、35、36
STM32入门开发 介绍IIC总线、读写AT24C02(EEPROM)(采用模拟时序)
Enterprise WeChat group: robot timing reminder function database configuration