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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:57:22+00:00 2026-05-25T12:57:22+00:00

How do you do write an HttpPut request with authentication on Android? (I’m trying

  • 0

How do you do write an HttpPut request with authentication on Android?

(I’m trying to work around using HttpURLConnection, which seems to serious have bugs (at least in Android 2.2) but GET works fine. I’d like to send a JSON representation of an array, and I have correct credentials already set using PasswordAuthentication.)

  • 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-25T12:57:23+00:00Added an answer on May 25, 2026 at 12:57 pm

    Here’s one general solution.

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, this.CONNECT_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParameters, this.CONNECT_TIMEOUT);
    
    DefaultHttpClient client = new DefaultHttpClient(httpParameters);
    
    // Retrieve user credentials.
    SharedPreferences settings = context.getSharedPreferences("LOGIN", 0);
    String loginNameString = settings.getString("login_name", null);
    String passwordString = settings.getString("password", null);
    
    UsernamePasswordCredentials credentials = 
                 new UsernamePasswordCredentials(loginNameString, passwordString);
    AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
                 client.getCredentialsProvider().setCredentials(authScope, 
                                                                  credentials);
    
    HttpPut put = new HttpPut(UPLOAD_URL);
    
    try
    {
        put.setEntity(new StringEntity(responseJSONArray.toString(),    
                           SERVER_PREFERRED_ENCODING));
        put.addHeader("Content-Type", "application/json");
        put.addHeader("Accept", "application/json");
        HttpResponse response = client.execute(put);
    
        // 200 type response.
        if (response.getStatusLine().getStatusCode() >= HttpStatus.SC_OK &&
        response.getStatusLine().getStatusCode() < HttpStatus.SC_MULTIPLE_CHOICES)
        {
          // Handle OK response etc........
        }
    }
    catch (Exception e)
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Write a class ListNode which has the following properties: int value; ListNode *next; Provide
Write a program to access the function foo using the structure structure2. typedef struct
I write my debug information to a file using a separate thread. During startup,
I write a router that takes the path of a request, match it against
I am trying to write a ruby app to update Google Contact Photos but
Write a function spaced(s) that outputs spaces and a dashdot border around a string
Write a function which finds a substring in a string and replaces all such
Write a function which has: input: array of pairs (unique id and weight) length
I write code in isolation, that is I work for myself. I need some
Write a function called swap which has a prototype of void swap (int&, int&);

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.