Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 224839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:21:17+00:00 2026-05-11T19:21:17+00:00

Thanks to this thread How to download and save a file from Internet using

  • 0

Thanks to this thread How to download and save a file from Internet using Java?
I know how to download a file, now my problem is that I need to authenticate on the sever from which I’m dowloading. It’s an http interface to a subversion server. Which field do I need to look up into ?

Using the code posted in the last comment, I get this exception:

java.io.IOException: Server returned HTTP response code: 401 for URL: http://myserver/systemc-2.0.1.tgz
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305)
    at java.net.URL.openStream(URL.java:1009)
    at mypackage.Installer.installSystemc201(Installer.java:29)
    at mypackage.Installer.main(Installer.java:38)

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:21:18+00:00Added an answer on May 11, 2026 at 7:21 pm

    You extend the Authenticator class and register it. The javadocs at the link explain how.

    I don’t know if this works with the nio method that got the accepted answer to the question, but it for sure works for the old fashioned way that was the answer under that one.

    Within the authenticator class implementation, you are probably going to use a PasswordAuthentication and override the getPasswordAuthentication() method of your Authenticator implementation to return it. That will be the class which is passed the user name and password you need.

    Per your request, here is some sample code:

    public static final String USERNAME_KEY = "username";
    public static final String PASSWORD_KEY = "password";
    private final PasswordAuthentication authentication;
    
    public MyAuthenticator(Properties properties) {
        String userName = properties.getProperty(USERNAME_KEY);
        String password = properties.getProperty(PASSWORD_KEY);
        if (userName == null || password == null) {
            authentication = null;
        } else {
            authentication = new PasswordAuthentication(userName, password.toCharArray());
        }
    }
    
    protected PasswordAuthentication getPasswordAuthentication() {
        return authentication;
    }
    

    And you register it in the main method (or somewhere along the line before you call the URL):

    Authenticator.setDefault(new MyAuthenticator(properties));
    

    The usage is simple, but I find the API convoluted and kind of backwards for how you typically think about these things. Pretty typical of singleton design.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 335k
  • Answers 335k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Edit Oh, I misunderstood your question apparently. Here is how… May 14, 2026 at 3:37 am
  • Editorial Team
    Editorial Team added an answer Due to the fact you require a GUI and user… May 14, 2026 at 3:37 am
  • Editorial Team
    Editorial Team added an answer Check std::next_permutation. May 14, 2026 at 3:37 am

Related Questions

I want to start a job in a new thread or using backgroundworker to
I'm starting to implement a simple daemon that basically fetches a file from an
I wonder if someone can help me. I'm trying to add a reference to
What is the most elegant way to implement this function: ArrayList generatePrimes(int n) This

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.