JSoup over VPN/proxy

前端 未结 3 1417
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 02:59

I\'m trying to use JSoup to scrape some pages that are on a staging server. To view the pages on the staging server with a browser I need to be connected to a VPN.

I

3条回答
  •  醉酒成梦
    2021-01-06 03:33

    To add on for ollo if your proxy needs username/password authentication.

    final String authUser = ;
    final String authPassword = ;
    Authenticator.setDefault(
       new Authenticator() {
          public PasswordAuthentication getPasswordAuthentication() {
             return new PasswordAuthentication(
                   authUser, authPassword.toCharArray());
          }
       }
    );
    
    System.setProperty("http.proxyHost", );
    System.setProperty("http.proxyPort", );
    System.setProperty("http.proxyUser", authUser);
    System.setProperty("http.proxyPassword", authPassword);
    
    Document doc = Jsoup.connect("http://your.url.here").get();
    

提交回复
热议问题