【问题标题】:Unable to tunnel through proxy - Jsoup无法通过代理隧道 - Jsoup
【发布时间】:2018-01-14 10:20:57
【问题描述】:

我在创建 HTTP 连接时遇到以下异常。

2017-08-07 17:07:43,219 ERROR au.com.scraper.sites.ScraperSite - Exception in parsing Categories: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Forbidden" at line number 153
java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Forbidden"
    at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2085)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:563)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:540)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:227)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:216)
    at org.jsoup.Jsoup.parse(Jsoup.java:183)
    at au.com.scraper.sites.ScraperSite.getCategories(ScraperSite.java:127)
    at au.com.scraper.sites.AScraperSites.execute(AScraperSites.java:74)
    at au.com.scraper.Scraper.main(Scraper.java:88)

下面是我的代理配置。

Authenticator.setDefault(new ProxyAuthenticator("user_name", "password"));
System.setProperty("https.proxyHost", server);
System.setProperty("https.proxyPort", port);
System.setProperty("http.proxyHost", server);
System.setProperty("http.proxyPort", port);

下面是我的代理验证器类。

package au.com.scraper;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
public class ProxyAuthenticator extends Authenticator
{
    public ProxyAuthenticator(String user, String password)
    {
        this.user = user;
        this.password = password;
    }
    protected PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication(user, password.toCharArray());
    }
    private String user;
    private String password;
}

谁能说明为什么会出现这个问题?

【问题讨论】:

  • 你试过禁用 disabledSchemes 吗? stackoverflow.com/a/41806109/6503002
  • 能否请您也发布您的ProxyAuthenticator 课程的代码。
  • @SubOptimal ...我已经更新了 ProxyAuthenticator 类。
  • 代码正确。用户名和/或密码不正确。或者也许 JSoup 替换了您的 Authenticator,这意味着它还有一些您需要使用的其他 API。
  • @EJP 感谢您的 cmets。代码是正确的。如果更新了用户名/密码,需要重启JVM。我已经重新启动了我的机器,令人惊讶的是它工作正常。

标签: java proxy jsoup tunneling


【解决方案1】:

您的代理服务器可能会阻止该网址,当网址是本地地址并且您的代理服务器将阻止该地址时,我们可能会遇到此问题。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-08-02
  • 1970-01-01
  • 2013-02-11
  • 2017-11-21
  • 2017-03-04
  • 2011-11-15
  • 2013-05-08
相关资源
最近更新 更多