By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,797 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,797 IT Pros & Developers. It's quick & easy.

Problem in connecting to a proxy

P: n/a
Hi,
i need to see if a user enters the correct username/password to
authenticate to a proxy. My problem is... through the following code,
i am
able to connect to a proxy with even invalid username/passwords.
Suppose
if the valid username and password to a proxy is test/test , i am able
to connect to the proxy using x/x . the response code returned is
always 200. Please advice..

################################

public static boolean isValidProxyAccount(String proxyServer,String
proxyPort,String proxyLogin,String proxyPassword) throws IOException
{
String go_url = new String ("http://www.google.com/");
boolean VALID_STATUS = true;

try{
URL url = new URL(go_url);

System.getProperties().put("proxySet",
"true");
System.getProperties().put("http.proxyHost", proxyServer);
System.getProperties().put("http.proxyPort", proxyPort);

HttpURLConnection con = (HttpURLConnection)
url.openConnection();
Base64Encoder b1 = new
Base64Encoder(proxyLogin+":"+proxyPassword);
con.setAllowUserInteraction(true);
String enStrProxy = "Basic "+ b1.processString();
con.setRequestProperty("Proxy-Authorization", enStrProxy);

int code = con.getResponseCode();
String retMsg = con.getResponseMessage();

System.out.println("code::"+code);
System.out.println("retMsg::"+retMsg);

System.getProperties().put("proxySet", "false");
System.getProperties().remove("http.proxyHost");
System.getProperties().remove("http.proxyPort");

con.disconnect();

if (code != 200){
VALID_STATUS = false;
throw new IOException("Failed to connect to CCO: "+retMsg);
}
}catch (Exception ex){
System.out.println(ex.getMessage());
throw new IOException(ex.getMessage());
}//catch
return VALID_STATUS;
}
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.