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 8932695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:22:15+00:00 2026-06-15T09:22:15+00:00

My app needs to connect to multiple servers, each with their own username/password pairs.

  • 0

My app needs to connect to multiple servers, each with their own username/password pairs. However The example provided in Android’s javadoc does not consider multiple hosts with different sets of username/password:


 Authenticator.setDefault(new Authenticator() {
     protected PasswordAuthentication getPasswordAuthentication() {
       return new PasswordAuthentication(username, password.toCharArray());
}); }

This sets the VM-wide authentication handler, and has no way to identify which host we are trying to connect to. Is there a way that I can use HttpUrlConenction and handle HTTP Authentication with different user/passes for different hosts?

  • 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-06-15T09:22:16+00:00Added an answer on June 15, 2026 at 9:22 am

    Use Authenticator’s getRequestingHost() method.

    Authenticator.setDefault(new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            if (this.getRequestingHost() != null)
                if (this.getRequestingHost().contains("a-site.com")
                    return new PasswordAuthentication(aUsername, aPassword.toCharArray());
                else if (this.getRequestingHost().contains("b-site.com")
                    return new PasswordAuthentication(bUsername, bPassword.toCharArray());
            return null;
        });
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple app processes that each connect to servers and receive data from
I have an iPhone app which allows multiple iPhones to connect to each other
I'm developing an Android app which needs to connect to a .NET SOAP web
I have an android app that needs to connect frequently to the server to
My app needs to have multiple screen e.g. one login page then another page
I'm building a Rails app that needs to connect to a custom TCP data
I'm researching how to code an iPhone app that needs to connect to an
I have a java app that runs on multiple computers and they all connect
My App needs to connect to and grab data from a MySQL database sitting
I'm doing an app that needs to connect with a login form to the

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.