????????????
????????????????????????У??????????????????????ж???
????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);