Java???HttpProxy?????
???????????? ???????[ 2015/8/17 13:37:27 ] ???????????????? ???????????
????????????
????????????????????????У??????????????????????ж???
????1 ???????http????????api??????????????
????2 ????????????????????????????????restful????
????????????????????????URLConnection????apache????httpclient????????????????????á?
???????????????????????????????????????google??twitter??tumblr?????API????
??????????gfw????£????????????????????????...
?????e??????????????????????proxy???????
???????????
????1 http?????????
???????黨??????????????VPN????http??????????
????2 ???????????
??????????chrome switchyOmega??????????????????????IE??????
???????????????????????
??????????
?????????????????????裺
?????????????????????????
??????????Java?????System.setProperty????????http????????????£?
????System.setProperty("http.proxySet"?? "true");
????System.setProperty("http.proxyHost"?? proxyHost);
????System.setProperty("http.proxyPort"?? "" + proxyPort);
????// ???https????????
????System.setProperty("https.proxyHost"?? proxyHost);
????System.setProperty("https.proxyPort"?? "" + proxyPort);
????????Java?????????????ο???http://docs.oracle.com/javase/6/docs/technotes/guides/net/properties.html
??????????????Proxy?????????????????URLConnection?????
????// ?????proxy????
????Proxy proxy = new Proxy(Proxy.Type.HTTP?? new InetSocketAddress(proxyHost?? proxyPort));
????// ????????
????URL u = new URL(url);
????URLConnection conn = u.openConnection(proxy);
??????????????????
???????????????????????????????URLConnection?????????????????setProperty????????????????????????????
??????????????????У??
????????????У?????д??http?????????????????base64???????????Proxy-Authorization???
????String headerKey = "Proxy-Authorization";
????String encoded = new String(Base64.encodeBase64((new String(proxyUser + ":" + proxyPass).getBytes())));
????String headerValue = "Basic " + encoded;
????conn.setRequestProperty(headerKey?? headerValue);
??????????????????????????????????????÷????https???????????????????????
??????????????Authenticator????????????????????
public static class MyAuthenticator extends Authenticator {
String userName;
String password;
public MyAuthenticator (String userName?? String password) {
this.userName = userName;
this.password = password;
}
/**
* ????????????У??????????
*/
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName?? password.toCharArray());
}
}
??????????????????У???????
????MyAuthenticator auth = new MyAuthenticator(proxyUser?? proxyPass);
????Authenticator.setDefault(auth);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11