|  |      1rain0002009      2024-03-08 13:21:49 +08:00 我很好奇 前端请求不是在浏览器发起的 关服务器有没有外网有什么关系 | 
|  |      2IvanLi127      2024-03-08 13:35:48 +08:00 服务器不通外网和前端有啥关系,客户机子也不通外网吗? | 
|  |      3codespots      2024-03-08 13:38:34 +08:00 就一个 JSONP 接口而已,前端不懂? | 
|  |      4CHTuring      2024-03-08 13:43:18 +08:00 前端调用 JS SDK 和服务器有啥关系... | 
|      5caiqichang      2024-03-08 14:22:19 +08:00  1 让前端写个全局的 fetch 和 xhr 拦截替换,像这样 ```javascript const original_fetch = window.fetch window.fetch = (request, options) => { if (typeof request === "string") { request = "https://bing.com" }else if (request instanceof Request) { request.url = "https://bing.com" } return original_fetch(request, options) } const original_xhr_open = XMLHttpRequest.prototype.open XMLHttpRequest.prototype.open = function(method, url, async, user, password) { url = "https://bing.com" return original_xhr_open.apply(this, arguments) } fetch("https://google.com").finally() const xhr = new XMLHttpRequest() xhr.open("GET", "https://google.com") xhr.send() ``` | 
|      6caiqichang      2024-03-08 14:25:53 +08:00 #5 xhr 那里写错了 return original_xhr_open.apply(this, [method, url, async, user, password]) | 
|      7SZhan OP @rain0002009 是这样的,整个系统被限制在了政务网内访问,自然客户使用的机器也是不通外网的,所以我的想法是把这个接口也做拦截,然后替换成我在服务器上做的代理地址 | 
|      8SZhan OP @caiqichang #5 明白了,我大概看了下,这个其实就是全局拦截这个请求接口,然后替换成目标地址去访问对吧? | 
|      11SZhan OP @CHTuring 因为浏览器也是在政务内网里的诶,客户的工作环境是一台公网、一台内网,只能用内网的机器访问系统,所以这就导致了只能借助这个内网环境下,唯一可访问公网的服务器做代理。我能想到的办法只有这样    | 
|  |      12NerbraskaGuy      2024-03-08 14:57:35 +08:00 刚好搜了下,这个应该算解决方法,相当于手动拦截: https://blog.csdn.net/weixin_58631631/article/details/133773423 |