为什么浏览器请求不通过我的代理服务器?

发布于 2024-11-04 20:38:48 字数 768 浏览 1 评论 0原文

我今天尝试使用基本的 HTTP 服务器在 node.js 中编写一个简单的代理,我意识到在 Firefox 中,当我重新加载代理时,我可以看到一个请求。但是,当我加载任何页面时,它似乎没有通过我的代理。我可以curl服务器,它工作得很好。但为什么浏览器不使用我的代理?

代码看起来像:

var http = require('http');

var listener = function(request, response) {
  console.log('hi');

  response.write("200");
  response.end();
};

var server = http.createServer(listener);
server.listen(8000, undefined, function() {
  console.log('Server has started on 8000');
});

我只是在寻找改变请求标头的东西,尽管反向代理也很酷。

编辑:这就是我将浏览器指向代理的方式。在 Firefox 中,首选项 ->高级->网络->设置

我尝试将“手动代理配置”下的 HTTP 代理设置为 127.0.0.1:8000 - 这似乎做了一些事情,因为我的所有页面都无法加载,但我在代理服务器上没有看到任何活动。

我还尝试将 127.0.0.1:8000 放在“自动代理配置 URL”下,当我配置它时,它会发送一个请求,但之后不会代理任何内容。我想知道“自动”配置正在寻找什么样的响应......

I tried writing a simple proxy in node.js today with a basic HTTP server, I realized in Firefox when I reload the proxy, I can see a request. However, when I load any page, it doesn't seem to be going through my proxy. I can curl the server, and it works fine. But why is the browser not using my proxy?

The code just looks like:

var http = require('http');

var listener = function(request, response) {
  console.log('hi');

  response.write("200");
  response.end();
};

var server = http.createServer(listener);
server.listen(8000, undefined, function() {
  console.log('Server has started on 8000');
});

I'm just looking for something that changes the header of the request, though a reverse proxy would also be cool.

Edit: This is how I'm pointing my browser to my proxy. In Firefox, preferences -> advanced -> Network -> Settings

I tried to setting the HTTP Proxy under "Manual proxy configuration" to 127.0.0.1:8000 - that seems to do something, cuz all my pages fail to load, but I don't see any activity on my proxy server.

I also tried to just put 127.0.0.1:8000 under "Automatic proxy configuration URL" which sends a request when I just configure it, but nothing is proxied afterwards. I'm wonder what kind of response the "automatic" configuration is looking for...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠栀 2024-11-11 20:38:48

你写的代码不是代理服务器吗?它只是一个 HTTPd 响应程序,这就是为什么你的 curl 脚本可以“工作”,但 Firefox 却不能

举一个已经在线的例子, http://catonmat.net/http-proxy-in-nodejs,您将看到,除了在节点中设置 HTTPd 之外,您还向被代理的服务器调度 HTTP 调用并耗尽那个输出返回到浏览器的响应。

The code you have written isn't a proxy server? It's just an HTTPd responder, which is why your curl script 'works' but firefox doesn't

Taking an example already online, http://catonmat.net/http-proxy-in-nodejs, you will see that as well as setting up the HTTPd in node, you have the dispatch HTTP calls to the server being proxied and drain that output back into the response to your browser.

城歌 2024-11-11 20:38:48

在 Firefox 中,您想要设置手动代理配置 -> Http 代理:127.0.0.1 和您的端口 8000

检查“对所有协议使用此代理服务器”

这对我有用:)

也许您有另一台服务器在 8000 上运行?

In firefox, you want to set Manual Proxy configuration -> Http Proxy: 127.0.0.1 and your Port 8000

Check "Use this proxy server for all protocols"

That works for me :)

Maybe you have another server running on 8000 ?

七月上 2024-11-11 20:38:48

要使用 Charles 捕获到 localhost 的流量,您需要使用 http://localhost./ (是的,在结尾)。

请参阅此处的文档:
http://www.charlesproxy.com/documentation/faqs /localhost-traffic-doesnt-appear-charles

To use Charles to capture traffic to localhost you need to use http://localhost./ (yes, with a dot on the end).

See the documentation here:
http://www.charlesproxy.com/documentation/faqs/localhost-traffic-doesnt-appear-in-charles

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文