External Libraries

Set Jsoup proxy in Java example

Set Jsoup proxy in Java example shows how to set proxy with Jsoup in Java. Example also shows how to set Jsoup proxy for HTTP, HTTPS and specify proxy username and password.

How to set Jsoup proxy?

If you are behind the internet proxy, you will get “java.net.SocketTimeoutException: connect timed out” exception while trying to connect to any URL using Jsoup like given below. (time out full example)

You need to set the proxy before you can access any URLs using Jsoup. Under the hood, Jsoup uses Java’s built-in Connection and HTTPURLConnection classes. That means we can set the proxy in the same standard Java way using system properties.

Setting Jsoup HTTP proxy

Use setProperty method of System class to set proxy host and proxy port properties before you connect to a URL using Jsoup as given below.

Above examples sets “” as proxy host and “3128” as proxy port. Change these values accordingly to set Jsoup proxy.

Setting Jsoup HTTPS proxy

If you are trying to parse HTTPS pages using Jsoup, you also need to set Jsoup HTTPS proxy. It can be done by setting below given properties.

Setting Jsoup proxy authentication

Does your proxy server need the authentication (username and password) to access the internet? If yes, you also need to set proxy username and password using below given properties.



Additionally, it is always a best practice to set user agent and referrer in Jsoup while making a connection. Also visit Jsoup examples to learn more about Jsoup.

Please let us know your views in the comments section below.

Want to learn quickly?
Try one of the many quizzes. I promise you will not be disappointed.


About the author



rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.


  • code is as follows:

    import java.io.IOException;

    import org.jsoup.Jsoup;

    public class JsoupSetProxyExample {

    public static void main(String[] args) {


    //set HTTP proxy host to (localhost)
    System.setProperty(“http.proxyHost”, “”);

    //set HTTP proxy port to 3128
    System.setProperty(“http.proxyPort”, “80”);
    System.setProperty(“http.proxyUser”, “user_id”);
    System.setProperty(“http.proxyPassword”, “password”);

    String strText =
    .timeout(10 * 1000)


    }catch(IOException ioe){
    System.out.println(“Exception: ” + ioe);


    • You need to provide proxy user id and password in order for this to work.

      System.setProperty(“http.proxyUser”, “your_user_id”);
      System.setProperty(“http.proxyPassword”, “your_password”);

      • yes i provided the my proxy user_id and my_password , i have not posted in this web page.
        in following order

        System.setProperty(“http.proxyHost”, “”);
        System.setProperty(“http.proxyPort”, “80”);
        System.setProperty(“http.proxyUser”, “my_user_id”);
        System.setProperty(“http.proxyPassword”, “my_password”);

        but the same exception is coming as below:

        Exception: org.jsoup.HttpStatusException: HTTP error fetching URL. Status=407, URL=http://htmlunit.sourceforge.net/gettingStarted.html

  • Hi !
    So you set the proxy for the whole connections from the JVM.
    Do you have an idea to set the proxy for this Jsoup.connect() only ?

Your email address will not be published. Required fields are marked *