import java.io.*;
import java.net.*;
class Test1 extends Authenticator
{
char password[]={1,2,3,4,5,6,7,8};
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("admin",password);
}
}
public class Test
{
public static void main(String args[]) throws IOException
{
Authenticator.setDefault(new Test1());
URL url=new URL("http://192.168.1.1/");
InputStream in=new BufferedInputStream(url.openStream());
Reader r=new InputStreamReader(in);
int c;
while((c=r.read())!=-1)
{
System.out.print((char)c);
}
}
}
报错是这样的Exception in thread "main" java.net.ProtocolException: Server redirected too many times (20)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at Test.main(Test.java:19)