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

  • SEARCH
  • Home
  • 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 6191403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:45:29+00:00 2026-05-24T02:45:29+00:00

I was trying to connect to some host like this url = new URL(urlString);

  • 0

I was trying to connect to some host like this

                url = new URL(urlString);
                BufferedReader in = new BufferedReader(
                                new InputStreamReader(
                                url.openStream()));

but I always get MalformedException – permission denied, I need to provide username and password ( which I know ) but I don’t know how, there is no constructor in URL with those parametere neither setusername/password methods. Where to put username and password ?

  • 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-24T02:45:30+00:00Added an answer on May 24, 2026 at 2:45 am

    I had do this in a previous project. In order to access a protected resource you need to use the Authenticator class.

    The username and password go in the variables defined for them towards the end but they do not have to hard coded, you can externalize them using java properties.

    Here is an old snippet

    // Install the custom authenticator
    Authenticator.setDefault(new MyAuthenticator());
    
    // Access the page
    try {
        // Create a URL for the desired page
        URL url = new URL("THE URL YOU NEED TO OPEN/ACCESS");
    
        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {
            // str is one line of text; readLine() strips the newline character(s)
        }
        in.close();
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    
    public class MyAuthenticator extends Authenticator {
        // This method is called when a password-protected URL is accessed
        protected PasswordAuthentication getPasswordAuthentication() {
            // Get information about the request
            String promptString = getRequestingPrompt();
            String hostname = getRequestingHost();
            InetAddress ipaddr = getRequestingSite();
            int port = getRequestingPort();
    
            // Get the username from the user...
            String username = "myusername";
    
            // Get the password from the user...
            String password = "mypassword";
    
            // Return the information
            return new PasswordAuthentication(username, password.toCharArray());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to connect to oracle server located at some IP address but
I'm trying to connect to an HTTPS URL, but I need to use client
I'm trying to connect to some host, using invalid port, and i want to
I'm trying to design some bookmarklets right now, that connect back to a server
I'm trying to connect from a host (PC or other) to a mobile cellular
I am trying to get an solution but i have found any thing on
I've been trying to get sqlplus to connect to Oracle from my OS X
Having some issues with this search engine I am trying to put together. I'll
I am trying to connect a Stellaris LM3S8962 evaluation kit to a linux host
I've spend some time trying to get information about users from my OenLDAP server.

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.