代码如下
说的是Authenticator类可实现向网站提供口令 但为什没登进去呢
import java.io.*;
import java.net.*;public class Test {
public static void main(String[] args) {
Authenticator.setDefault(new Authentication());
try {
int n = -1;
byte b[] = new byte[118];
String s1 = new String("http://10.253.7.29:5555/");
URL url = new URL(s1);
InputStream is = url.openStream();
FileOutputStream os = new FileOutputStream(new File("schedule.html"));
while ((n = is.read(b)) != -1) {
os.write(b, 0, n);
}
os.close();
} catch (MalformedURLException e) {
System.out.println("don't find this file" + e);
} catch (IOException el) {
System.out.println("io error" + el);
}
}
}
class Authentication extends Authenticator{
public PasswordAuthentication getPasswordAuthentication(){
String username=new String("河西");
char[] password="123456".toCharArray();
return new PasswordAuthentication(username,password);
}
}
说的是Authenticator类可实现向网站提供口令 但为什没登进去呢
import java.io.*;
import java.net.*;public class Test {
public static void main(String[] args) {
Authenticator.setDefault(new Authentication());
try {
int n = -1;
byte b[] = new byte[118];
String s1 = new String("http://10.253.7.29:5555/");
URL url = new URL(s1);
InputStream is = url.openStream();
FileOutputStream os = new FileOutputStream(new File("schedule.html"));
while ((n = is.read(b)) != -1) {
os.write(b, 0, n);
}
os.close();
} catch (MalformedURLException e) {
System.out.println("don't find this file" + e);
} catch (IOException el) {
System.out.println("io error" + el);
}
}
}
class Authentication extends Authenticator{
public PasswordAuthentication getPasswordAuthentication(){
String username=new String("河西");
char[] password="123456".toCharArray();
return new PasswordAuthentication(username,password);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货