Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All TopicsHai ..
I try to use this function but my pc not join to any domain and using proxy server to connect to internet ..
i try this .. function
the problem is .. i need pass DOMAIN name to connect to internet ...
please give me advice .. thank .
// The Authenticator class **************************
import java.io.*;
import java.net.*;
public class URLAuthenticator {
/**
* The alphabet dictionary used for encoding
*/
public static final char [ ] alphabet = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55
'4', '5', '6', '7', '8', '9', '+', '/' }; // 56 to 63
/**
* Encode a string
* @param s the string to encode
* @return the encoded string
*/
public static String encode(String s) {
return encode(s.getBytes());
}
/**
* Encode a byte[] array
* @param octetString the byte[] buffer to encode
* @return the encoded string
*/
public static String encode(byte[] octetString) {
int bits24;
int bits6;
char[] out = new char[((octetString.length - 1) / 3 + 1) * 4];
int outIndex = 0;
int i = 0;
while ((i + 3) <= octetString.length) {
// store the octets
bits24 = (octetString[i++] & 0xFF ) << 16;
bits24 |= (octetString[i++] & 0xFF ) << 8;
bits24 |= (octetString[i++] & 0xFF ) << 0;
bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x00000FC0) >> 6;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x0000003F);
out[outIndex++] = alphabet[bits6];
}
if (octetString.length - i == 2) {
// store the octets
bits24 = (octetString[i] & 0xFF ) << 16;
bits24 |= (octetString[i + 1] & 0xFF) << 8;
bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x00000FC0) >> 6;
out[outIndex++] = alphabet[bits6];
// padding
out[outIndex++] = '=';
} else if (octetString.length - i == 1) {
// store the octets
bits24 = (octetString[i] & 0xFF) << 16;
bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = alphabet[bits6];
// padding
out[outIndex++] = '=';
out[outIndex++] = '=';
}
return new String(out);
}
public static void authenticate(URLConnection
String encoding = encode((user + ":" + password).getBytes());
uc.setRequestProperty("Aut
}
/**
* Create an authenticated URLConnection
* @param u the URL to open the connection from
* @param user the users name
* @param password the users password
* @return the authenticated URLConnection
*/
public static URLConnection openConnection(URL u, String user, String password) {
URLConnection result = null;
try {
result = u.openConnection();
if (result != null) {
authenticate(result, user, password);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
/**
* Get a URL content object through an authenticated URLConnection
* @param u the URL to get the content from
* @param user the users name
* @param password the users password
* @return the content of the URL
*/
public static Object getContent(URL u, String user, String password) {
Object result = null;
try {
URLConnection uc = openConnection(u, user, password);
if (uc != null) {
result = uc.getContent();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
/**
* Get a URL InputStream object through an authenticated URLConnection
* @param u the URL to get the InputStream object from
* @param user the users name
* @param password the users password
* @return the InputStream object of the URL
*/
public static InputStream openStream(URL u, String user, String password) {
InputStream result = null;
try {
URLConnection uc = openConnection(u, user, password);
if (uc != null) {
result = uc.getInputStream();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
public static void main(String args[])throws Exception {
URL loader = null;
String line = "";
System.setProperty("java.p
System.setProperty("proxyH
System.setProperty("proxyP
try {
loader = new URL("http://www.yahoo.com.
} catch(MalformedURLExceptio
System.out.println("Invali
}
try {
URLConnection con = URLAuthenticator.openConne
new InputStreamReader(con.getI
BufferedReader br = new BufferedReader(new InputStreamReader(con.getI
while ((line = br.readLine()) != null)
if(line!=null)
System.out.println(line);
br.close();
}
catch(IOException e) {
e.printStackTrace();
}
}
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: userquinPosted on 2002-06-04 at 04:56:25ID: 7053513
Comments are available to members only. Sign up or Log in to view these comments.