HttpURLConnection connection = (HttpURLConnection)url.openConnection();
//String authString = "pfg" + ":" + "123";
byte [] b1 = authString.getBytes();
String auth = "Basic " +Base64Coder.getInstance().encode(b1, 0, b1.length);
//connection.setRequestProperty("Proxy-Authorization", auth); // 我试过了这种方法,但是不行。//连接指定的资源
connection.connect();
InputStream is = connection.getInputStream();Http下载文件需要用户名和密码,我该如何实现呢?
//String authString = "pfg" + ":" + "123";
byte [] b1 = authString.getBytes();
String auth = "Basic " +Base64Coder.getInstance().encode(b1, 0, b1.length);
//connection.setRequestProperty("Proxy-Authorization", auth); // 我试过了这种方法,但是不行。//连接指定的资源
connection.connect();
InputStream is = connection.getInputStream();Http下载文件需要用户名和密码,我该如何实现呢?
使用下面的方法
Authenticator.setDefault(new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("pioneer", "ind4sh".toCharArray());
}
});