Java???HttpProxy?????
???????????? ???????[ 2015/8/17 13:37:27 ] ???????????????? ???????????
???????????
?????????
/**
* ??????????
*
* <pre>
* ???????????????????????(https ?????????)
* ????????????????????????
*
*
* https???????
* Unable to tunnel through proxy. Proxy returns "HTTP/1.0 407 Proxy Authentication Required"
* ???????????????
*
* </pre>
*
* @author tzz
* @createDate 2015??7??23??
*
*/
public class ProxyTest {
private static String proxyHost = "xxx.xxxxx.com";
private static int proxyPort = 8080;
private static String proxyUser = "user";
private static String proxyPass = "pass";
public static void main(String[] args) {
String url = "https://www.google.com/";
String content = doProxy(url);
System.out.println("Result :=================== " + content);
}
/**
* ??????????????????
*
* @param url
* @return
*/
public static String doProxy(String url) {
// ??????????
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);
// ???????У????
setDefaultAuthentication();
//???????
try {
URL u = new URL(url);
URLConnection conn = u.openConnection();
HttpsURLConnection httpsCon = (HttpsURLConnection) conn;
httpsCon.setFollowRedirects(true);
String encoding = conn.getContentEncoding();
if (StringUtils.isEmpty(encoding)) {
encoding = "UTF-8";
}
InputStream is = conn.getInputStream();
String content = IOUtils.toString(is?? encoding);
return content;
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
/**
* ???????У????????
*/
public static void setDefaultAuthentication() {
BasicAuthenticator auth = new BasicAuthenticator(proxyUser?? proxyPass);
Authenticator.setDefault(auth);
}
}
????У????
/**
* ???sun.net????????
*
* @author tzz
* @createDate 2015??7??23??
*
*/
public static class BasicAuthenticator extends Authenticator {
String userName;
String password;
public BasicAuthenticator(String userName?? String password) {
this.userName = userName;
this.password = password;
}
/**
* Called when password authorization is needed. Subclasses should override the default implementation?? which returns null.
*
* @return The PasswordAuthentication collected from the user?? or null if none is provided.
*/
@Override
protected PasswordAuthentication getPasswordAuthentication() {
//System.out.println("DEBUG === use global authentication of password");
return new PasswordAuthentication(userName?? password.toCharArray());
}
}
????????????
???????????
????Unable to tunnel through proxy. Proxy returns "HTTP/1.0 407 Proxy Authentication Required"
?????????????????δ???????????????£????????url????https???????????Authenticator???????????á?
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
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????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????