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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:11:10+00:00 2026-06-07T02:11:10+00:00

Right, i have been working on trying to figure out basic authentication in android

  • 0

Right, i have been working on trying to figure out basic authentication in android so that i can pull json data down from a url. So far the basic authentication has seemed to cause me a lot of trouble. Finally after a good three days research I found an example online that was using a similar technique to pull xml down. This is what i have:

 String MY_APP_TAG = "basic.authentication";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    
    String username = "username";
    String host = "www.example.com";
    String password = "password";
    String urlBasePath = "http://www.example.com/api/core/v1/my";
    String urlApiCall_FindAllRepositories = urlBasePath;

    try {
        HttpClient client = new DefaultHttpClient();
        AuthScope as = new AuthScope(host, 80);
        UsernamePasswordCredentials upc = new UsernamePasswordCredentials(
                username, password);

        ((AbstractHttpClient) client).getCredentialsProvider()
                .setCredentials(as, upc);

        BasicHttpContext localContext = new BasicHttpContext();
        BasicScheme basicAuth = new BasicScheme();
        localContext.setAttribute("preemptive-auth", basicAuth);

        HttpHost targetHost = new HttpHost(host, 80, "http");
        HttpGet httpget = new HttpGet(urlApiCall_FindAllRepositories);
        HttpResponse response = client.execute(targetHost, httpget,
                localContext);

        HttpEntity entity = response.getEntity();
        Object content = EntityUtils.toString(entity);
        
     
        
        String decoded_password = new String(Base64.decode(content.toString(), Base64.DEFAULT));
        System.out.println("RESULT: " + decoded_password);

        Log.d(MY_APP_TAG, content.toString());
        System.out.println(content.toString().getBytes().toString());

    } catch (Exception e) {
        e.printStackTrace();
        Log.d(MY_APP_TAG, "Error: " + e);
    }

}
}

As you can see from the code I am passing the authentication and trying to decode the result using base 64. The strange thing is that this is what i am getting back:

07-04 21:55:01.726: D/gralloc_goldfish(639): Emulator without GPU emulation detected.

07-04 21:58:19.256: I/dalvikvm(753): threadid=3: reacting to signal 3

07-04 21:58:19.297: I/dalvikvm(753): Wrote stack traces to ‘/data/anr/traces.txt’

07-04 21:58:19.656: W/DefaultRequestDirector(753): Authentication error: Unable to respond to any of these challenges: {}

07-04 21:58:19.676: I/System.out(753): RESULT: �N�7���|�22 �

07-04 21:58:19.676: D/basic.authentication(753): ������������1Â0��÷¼ÂÊÒ!

07-04 21:58:19.676: D/basic.authentication(753): &ÄÄʬÄ4L¶£¿²îÎÊ

07-04 21:58:19.676: D/basic.authentication(753): 2Ëzc¦ùN&]]jð@6ÚOçð ��ñIf¸PÄKì^¨yMè¡é(½{ÕjÑ< `J£/C _RÇÝöLÿÃãaÃ÷²������

07-04 21:58:19.676: I/System.out(753): [B@412d87a0

07-04 21:58:19.746: I/dalvikvm(753): threadid=3: reacting to signal 3

07-04 21:58:19.756: I/dalvikvm(753): Wrote stack traces to ‘/data/anr/traces.txt’

07-04 21:58:19.946: D/gralloc_goldfish(753): Emulator without GPU emulation detected.

So as you can see I am getting some weird code back but its also stating that there is an authentication error.

can anyone help me please to try and figure out what is going on?

  • 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-07T02:11:12+00:00Added an answer on June 7, 2026 at 2:11 am

    Two things are happening here: you are performing a network operation on the main thread, and you are getting an ANR (application not responding) from Android. Change your app to use AsyncTask or similar. The second thing is that the data you are getting back is probably not what you expect, since Bae64 decoding seems to produce garbage. Dump the raw response and check/compare with results in a browser.

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

Sidebar

Related Questions

I have been trying to figure this out for a while now, but every
Currently working on trying to figure out asynchronous submission in ColdFusion. I always have
Okay I've been trying to figure this out for a while now. I have
I have been trying to create beta invites that each existing user can send
Me and 2 people have been trying to figure out what should be a
I been having trouble trying to figure this out. When I think I have
Alright I've been working on this for hours now and can't figure out my
Right now I have been trying to use Launchpad's API to write a small
I've been researching but I just can't seem to get it right. I have
I am very new to javascript and ajax/jquery and have been working on trying

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.