Trying to connect to an https://domain.com URL via Java and failingto do so

Discussion in 'Java' started by Rob, May 7, 2012.

  1. Rob

    Rob Guest

    Can anyone help me understand why this is not working:

    Here is the important part. When compiled and run:
    String Urlx="https://domain.com" // valid URL that comes up fine in a
    web browser
    System.setProperty("java.protocol.handler.pkgs",
    "com.sun.net.ssl.internal.www.protocol");
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    URL url = new URL(Urlx);
    in = url.openStream(); // Currently An IoException is thrown
    :

    It appears an IoException is thrown: java.io.IOException: Server
    returned HTTP response code: 403 for URL: https://domain.com

    Does anyone know why this might be happening and what if anything is
    missing? e.g missing .jar file? A different way to accomplish this in
    Java JDK?
    Rob, May 7, 2012
    #1
    1. Advertising

  2. Rob

    Daniel Pitts Guest

    Re: Trying to connect to an https://domain.com URL via Java andfailing to do so

    On 5/7/12 1:28 PM, Rob wrote:
    > Can anyone help me understand why this is not working:
    >
    > Here is the important part. When compiled and run:
    > String Urlx="https://domain.com" // valid URL that comes up fine in a
    > web browser
    > System.setProperty("java.protocol.handler.pkgs",
    > "com.sun.net.ssl.internal.www.protocol");
    > Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    > URL url = new URL(Urlx);
    > in = url.openStream(); // Currently An IoException is thrown
    > :
    >
    > It appears an IoException is thrown: java.io.IOException: Server
    > returned HTTP response code: 403 for URL: https://domain.com
    >
    > Does anyone know why this might be happening and what if anything is
    > missing? e.g missing .jar file? A different way to accomplish this in
    > Java JDK?
    >


    http://lmgtfy.com/?q=http 403

    It means the server doesn't like something about your request. Many
    websites don't allow Java's default User-Agent, for many reasons.
    Likely you are (perhaps unintentionally) violating the ToS of the site
    you're attempting to connect to.
    Daniel Pitts, May 7, 2012
    #2
    1. Advertising

  3. Rob

    Arne Vajhøj Guest

    Re: Trying to connect to an https://domain.com URL via Java andfailing to do so

    On 5/7/2012 4:28 PM, Rob wrote:
    > Can anyone help me understand why this is not working:
    >
    > Here is the important part. When compiled and run:
    > String Urlx="https://domain.com" // valid URL that comes up fine in a
    > web browser
    > System.setProperty("java.protocol.handler.pkgs",
    > "com.sun.net.ssl.internal.www.protocol");
    > Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    > URL url = new URL(Urlx);
    > in = url.openStream(); // Currently An IoException is thrown
    > :
    >
    > It appears an IoException is thrown: java.io.IOException: Server
    > returned HTTP response code: 403 for URL: https://domain.com
    >
    > Does anyone know why this might be happening and what if anything is
    > missing? e.g missing .jar file? A different way to accomplish this in
    > Java JDK?


    I don't think you need to specify any properties to use HTTPS in
    any recent Java.

    Whether that makes a difference or not I don't know.

    Arne
    Arne Vajhøj, May 7, 2012
    #3
  4. Rob

    Roedy Green Guest

    Re: Trying to connect to an https://domain.com URL via Java and failing to do so

    On Mon, 7 May 2012 13:28:01 -0700 (PDT), Rob <> wrote,
    quoted or indirectly quoted someone who said :

    >String Urlx="https://domain.com" // valid URL that comes up fine in a
    >web browser
    >System.setProperty("java.protocol.handler.pkgs",
    >"com.sun.net.ssl.internal.www.protocol");
    >Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    >URL url = new URL(Urlx);
    >in = url.openStream(); // Currently An IoException is thrown


    See http://mindprod.com/products1.html#HTTP

    You get use the GET class to fetch either http: or https:
    Java selects the https: handler transparently.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    Programmers love to create simplified replacements for HTML.
    They forget that the simplest language is the one you
    already know. They also forget that their simple little
    markup language will bit by bit become even more convoluted
    and complicated than HTML because of the unplanned way it grows.
    ..
    Roedy Green, May 8, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Subra Mallampalli
    Replies:
    0
    Views:
    417
    Subra Mallampalli
    Oct 2, 2003
  2. Subra Mallampalli
    Replies:
    0
    Views:
    435
    Subra Mallampalli
    Oct 2, 2003
  3. Subra Mallampalli
    Replies:
    0
    Views:
    130
    Subra Mallampalli
    Oct 2, 2003
  4. Subra Mallampalli

    Error when trying to connect over HTTPS using a client certificate.

    Subra Mallampalli, Oct 2, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    116
    Subra Mallampalli
    Oct 2, 2003
  5. Replies:
    2
    Views:
    260
Loading...

Share This Page