java 无需代理即可直接连接到 Internet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6954119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 18:00:44  来源:igfitidea点击:

Direct connection to Internet without Proxy

javanetworkingproxy

提问by Geek

Is it possible to make a Direct connection to the Internet without using a Proxy.

是否可以在不使用代理的情况下直接连接到 Internet。

Consider a case that my Organization has a Proxy and I use the DIRECT option given in the Java Proxy class.

考虑这样一种情况,我的组织有一个代理,我使用 Java 代理类中提供的 DIRECT 选项。

SocketAddress addr = new
InetSocketAddress("webcache.mydomain.com", 8080);
Proxy proxy = new Proxy(Proxy.Type.DIRECT, addr);

If you go by the documentation it states DIRECT which represents a direct connection, or absence of proxy.

如果您查看文档,它会指出 DIRECT 表示直接连接或没有代理。

Which is exactly the way it behaves. When I use this option, I dont have to give any Proxy details and I can access the content from the Internet.

这正是它的行为方式。当我使用此选项时,我不必提供任何代理详细信息,我可以从 Internet 访问内容。

I have three questions

我有三个问题

  1. As per my understanding if an Organization has a Proxy, all network traffic should get routed through the Proxy. No one should be able to access the Network directly ?
  2. I also noted that if I remove the Proxy details from IE, I can not access the Web :-( How can Java still do it ?
  3. If in any Organization you can access both with the Proxy and Directly, how does the firewall block certain sites ? How does the firewall even work ?
  1. 根据我的理解,如果组织有代理,则所有网络流量都应通过代理路由。应该没有人可以直接访问网络吗?
  2. 我还注意到,如果我从 IE 中删除代理详细信息,则无法访问 Web :-( Java 怎么还能这样做?
  3. 如果在任何组织中您都可以使用代理和直接访问,防火墙如何阻止某些站点?防火墙是如何工作的?

Thanks in advance.

提前致谢。

采纳答案by Geek

Not all Network traffic goes through a Proxy, if your Organization has a Proxy. You can still go ahead and establish a Direct connection to the Internet. Mostly the Organizations will block Direct connections and force you to use Proxies. Some times they might allow you to have a Restricted Direct connection, which allows certain URL's and denies other ones.

如果您的组织有代理,则并非所有网络流量都通过代理。您仍然可以继续建立与 Internet 的直接连接。大多数情况下,组织会阻止直接连接并强制您使用代理。有时,它们可能允许您拥有受限的直接连接,这允许某些 URL 并拒绝其他 URL。

回答by pap

Proxy proxy = new Proxy(Proxy.Type.DIRECT, addr);

Is not the proper way to create a direct (no proxy) proxy directive. You should do

不是创建直接(无代理)代理指令的正确方法。你应该做

Proxy proxy = Proxy.NO_PROXY

The internal implementation of the Socket class and the HttpURLConnection checks if proxy == Proxy.NO_PROXY(note: "==", not "equals()"!).

Socket 类和 HttpURLConnection 的内部实现检查是否proxy == Proxy.NO_PROXY(注意:“==”,而不是“equals()”!)。

It does NOT check if proxy.getType() == Proxy.Type.DIRECT.

它不检查是否proxy.getType() == Proxy.Type.DIRECT.

回答by KishoreK

2) You might have set the proxy in any system properties. If you are using any IDE, check the proxy setting of the IDE.

2) 您可能在任何系统属性中设置了代理。如果您使用任何 IDE,请检查 IDE 的代理设置。