-2

I am beginner in Network Programming. here is my very simple code:

System.setProperty("http.proxyHost","127.0.0.1");
URL url=new URL("http:\\www.google.com");
url.openConnection();   // Connection object is getting returned

My question is - If I am providing the proxy setting still my program is making direct connection with host . Why?

Roman C
  • 49,761
  • 33
  • 66
  • 176
user2653926
  • 610
  • 7
  • 23
  • 4
    Atleast leave a comment why a down vote. So I can understand my mistake – user2653926 Feb 14 '15 at 11:18
  • Please help anybody. Cannot resume my study prior of understanding this concept. – user2653926 Feb 14 '15 at 11:33
  • setting system property will not make it a proxy in java. See [this](http://stackoverflow.com/questions/8148024/how-to-get-url-connection-using-proxy-in-java#8561366) one for doing it the right way – Arkantos Feb 14 '15 at 12:11

1 Answers1

1

Having a read of the Java API Documentation for URL, there is no mention that setting a system property as you have would make any difference.

The documentation does make mention of another method, which may be what you're after.

http://docs.oracle.com/javase/7/docs/api/java/net/URL.html#openConnection(java.net.Proxy)

Additionally, your URL string should contain forward slashes rather than backslashes.

"http://www.google.com"
Frank
  • 108
  • 2
  • 5
  • The properties are documented here: http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html – greg-449 Feb 14 '15 at 12:57