File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Detecting browser proxy settings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Detecting browser proxy settings" Watch "Detecting browser proxy settings" New topic

Detecting browser proxy settings

Suresh Appagundi
Ranch Hand

Joined: Sep 22, 2003
Posts: 44
Hi all,

I need to get the proxy setting details before accessing any url using URL class (java net package).

In jdk 1.5 there is a class called ProxySelector, which is supposed to do the job. But it is failing.

Below is source code iam trying

package com.httpclient;

import java.lang.reflect.Type;
import java.util.List;

public class testURL {

* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedInputStream in;

HttpURLConnection conn;
BufferedReader bin;
URL u;
String fileContents="";
try {
ProxySelector ps = ProxySelector.getDefault();
URL url = new URL("");
URLConnection connection = url.openConnection();
List proxyList =;

int len = proxyList.size();
System.out.println("size : "+ len);
for (int i = 0; i < len; i++) {
Proxy p = (Proxy) proxyList.get(i);
InetSocketAddress addr = (InetSocketAddress) p.address();
if (addr == null) {

else {
InetAddress ip_addr = addr.getAddress();

int tcp_port = addr.getPort();
// Use the specified IP and port number as the proxy

System.out.println("IP ADDR " + ip_addr + "tcp_port " + tcp_port);

} catch (Exception e) {
// TODO Auto-generated catch block


Please help on solving this issue. Immediate response will be of very useful.

thanks in advance.
Simon Havenith

Joined: Mar 01, 2004
Posts: 4
Try adding the system property, like this

[ November 15, 2005: Message edited by: Simon Havenith ]
Casper Maxwell
Ranch Hand

Joined: Aug 04, 2005
Posts: 88
Why is this not working (JDK-1.5 option)?

How to detect Proxy Settings for Internet Connection
Simon Havenith

Joined: Mar 01, 2004
Posts: 4
It works for me. What issues are you having?
I agree. Here's the link:
subject: Detecting browser proxy settings
jQuery in Action, 3rd edition