我有一个 HTTP 代理,我想代理来自浏览器客户端应用程序的所有 HTTP 请求。
在命令行上,我可以通过以下方式代理请求:
curl https://code.sgo.to --proxy localhost:5555
Run Code Online (Sandbox Code Playgroud)
或这个:
var http = require("http");
var options = {
host: "proxy",
port: 8080,
path: "http://www.google.com",
headers: {
Host: "www.google.com"
}
};
http.get(options, function(res) {
console.log(res);
res.pipe(process.stdout);
});
Run Code Online (Sandbox Code Playgroud)
但是,在客户端上,path似乎并不是真正有效的path. 例如
fetch("http://localhost:5555http://code.sgo.to")
Run Code Online (Sandbox Code Playgroud)
看起来不太对劲。但
fetch("http://localhost:5555/http://code.sgo.to")
Run Code Online (Sandbox Code Playgroud)
破坏了我的标准代理,因为路径中有一个额外的内容/,它期望传递一个 URL。
有人知道浏览器中的等效项是什么(例如 throughfetch()或 through XMLHttpRequest)吗?
Eve*_*ert -2
浏览器不允许你这样做。
| 归档时间: |
|
| 查看次数: |
6805 次 |
| 最近记录: |