是否可以将代理添加到我的URL()。openStream()?
scanner = new Scanner(new URL(url).openStream());
我的代理人有用户名和密码
答案 0 :(得分:3)
也许你可以从这开始:
String proxyUser = "";
String proxyPassword = "";
String proxyAddress = "";
int proxyPort = 8080;
InetSocketAddress sa = new InetSocketAddress(proxyAddress, proxyPort);
Proxy proxy = new Proxy(Proxy.Type.HTTP, sa);
URLConnection conn = url.openConnection(proxy);
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String encodedUserPwd = encoder.encode((proxyUser + ":" + proxyPassword).getBytes());
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd);