/**
* 根据Url获取输入流
* @param urlPath 请求的待登陆Url
* @return InputStream 输入流
* @throws Exception
*/
public static InputStream getUrlInputStream(String urlPath) throws Exception{
URL url = new URL(urlPath);
URLConnection urlConnection = url.openConnection();
// 为URLConnection设置 "授权" 要求属性 (必须)
urlConnection.setDoOutput(true);
urlConnection.setConnectTimeout(1000 * 15);
urlConnection.setRequestProperty("Authorization", "Basic "
+ getUPString());
//防止屏蔽程序抓取而返回403错误
urlConnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
urlConnection.connect();
InputStream is = urlConnection.getInputStream();
return is;
}
/**
* 获取URL参数
* @return
*/
public static String getUPString(){
String userPassword = DocInfoPropertires.username + ":"
+ DocInfoPropertires.password;
String encoding = new BASE64Encoder().encode(userPassword
.getBytes());
return encoding;
}
妥妥的!!!