如何解决如何将带有用户名和密码的代理添加到Jsoup?
我正在开发一个Java应用程序,该应用程序需要通过代理(使用用户名和密码)连接到Internet。但这是行不通的。有人可以帮我解决这个问题吗?我的Java代码如下:
final String authUser = "username";
final String authPassword = "password";
Authenticator.setDefault(new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(authUser,authPassword.toCharArray());
}
});
System.setProperty("http.proxyHost","192.123.12.123");
System.setProperty("http.proxyPort","1234");
Document doc = null;
try {
doc = Jsoup
.connect("https://www.google.com").timeout(60000)
.header("Content-Language","en-US")
.get();
} catch (IOException e) {
e.printStackTrace();
}
解决方法
您可以尝试以下方法:
System.setProperty("http.proxyUser","username");
System.setProperty("http.proxyPassword","password");
或
System.setProperty("https.proxyUser","username");
System.setProperty("https.proxyPassword","password");
,
我遇到了这个错误:
java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
at java.base/sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2180)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:169)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:142)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:732)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:707)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:297)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:286)
at com.html.proxy.MyProxySelector.connectProxy(MyProxySelector.java:46)
at com.html.proxy.MyProxySelector.main(MyProxySelector.java:56)
我想通过代理访问网页(例如gooogle.com)(例如:“ 192.123.12.123:123”,并使用用户名和密码)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。