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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:01:42+00:00 2026-05-25T02:01:42+00:00

Below is a method I’m using to make calls to a REST API. It

  • 0

Below is a method I’m using to make calls to a REST API. It works fine with POST (i.e. param isHttpPOST=true), and returns results from the server (which requires basic authentication).

But when using the GET code path (isHttpPOST=false), the authentication fails, as if I provided no credentials at all. I cannot see why, as the auth code applies to POST and GET.

What else needs doing to authenticate on a GET request?

private static HttpResponse makeHttpApiCall(String url, String json, boolean isHttpPOST, String username, String password)
{
    DefaultHttpClient httpClient = new DefaultHttpClient();
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
    httpClient.getCredentialsProvider().setCredentials(new AuthScope("blah.com", 80), creds);
    HttpResponse response;
    try {
        if ( isHttpPOST )
        {
            HttpPost httppost    = new HttpPost(url);
            StringEntity se = new StringEntity(json);
            se.setContentEncoding("UTF-8");
            httppost.setHeader("Content-Type", "application/json");
            httppost.setEntity(se);
            response = httpClient.execute(httppost);
        }
        else
        {
            HttpGet get = new HttpGet(url);
            response = httpClient.execute(get);
        }
    } catch (ClientProtocolException e) {
        Trace.e(TAG, "There was a protocol based error making API call", e);
        return null;
    } catch (IOException e) {
        Trace.e(TAG, "There was an IO Stream related error making API call", e);
        return null;
    } catch (Exception e) {
        Trace.e(TAG, "Failed to get a response from API call (unknown error)", e);
        return null;
    }
    return response;

}
  • 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-25T02:01:42+00:00Added an answer on May 25, 2026 at 2:01 am

    i got the same problem, but the other way around, it works on GET but not on POST.

    if the server is yours, i would recommend to use a freeware called Wireshark, to check what’s going on in the transmition itself.

    using that tool, showed me that the client sometimes makes a first annonymous request before making a second authorized request, but then the server kinda loses it and doesn’t respond.. i still can’t solve this issue.. it’s driving me nuts.

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

Sidebar

Related Questions

In the below method calls from a single object, how to make the handler
I am using the below method to get the file names. But it returns
I'm using the below method to reply to mails coming in to a business
I want to fetch a method's comments,take below method for example: /** * Returns
Below method selects admin rights and returns bool from a cached DataTable, would it
I am using the below method between the 50lines of JQuery Code. From the
I am using below method for validating that one of radio button must be
trying to instantiate a Query in SubSonic using the below method (as it apparently
I am trying to get a total record count from the below Method using
I am using below method to draw string. -(void) drawRect:(CGRect)rect { NSString *mName =

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.