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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:07:35+00:00 2026-05-25T00:07:35+00:00

anyone help me how to POST authentication details to a restful web service and

  • 0

anyone help me how to POST authentication details to a restful web service and to get response from it.
I have to post Username, IsAuthenticated(ie. true or false), Password.Also explain the url encoding method too.
I have shown my code below. I am a Beginner in Android.

public class LoginActivity extends Activity
{
    String Username;
    String Password;
    String IsAuthenticated;
    String answer;

    @Override
     public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);
            try {
                POST(Username,Password,IsAuthenticated);
            } catch (Exception e) {
                e.printStackTrace();
            }
      }


     public String POST(String Username, String IsAuthenticated, String Password) {
         String Returned = null;
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost("http://......./Authenticate");

          try {
             List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
             // Your DATA
             nameValuePairs.add(new BasicNameValuePair("UserName", "Username"));
             nameValuePairs.add(new BasicNameValuePair("IsAuthenticated", "false"));
             nameValuePairs.add(new BasicNameValuePair("Password", "Password"));

             httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
             HttpResponse response = httpclient.execute(httppost);
             HttpEntity resEntity = response.getEntity();
             Returned = EntityUtils.toString(resEntity);

            System.out.println(Returned);
             Toast.makeText(this, Returned, Toast.LENGTH_LONG).show();
          } catch (ClientProtocolException e) {
             Toast.makeText(this, "There was an issue Try again later", Toast.LENGTH_LONG).show();
          } catch (IOException e) {
             Toast.makeText(this, "There was an IO issue Try again later", Toast.LENGTH_LONG).show();
             e.printStackTrace();
          }

          return Returned;
       }
}
  • 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-25T00:07:35+00:00Added an answer on May 25, 2026 at 12:07 am

    And I got the answer finally and working fine for me… I have posted the working code below.

        public class LoginActivity extends Activity
    {
        String Returned;
        @Override
         public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               setContentView(R.layout.main);
    
              try {
                  HttpClient httpclient = new DefaultHttpClient();
                  HttpPost post = new HttpPost("http://Your url here/");
                  StringEntity str = new StringEntity("Your xml code");
                  str.setContentType("application/xml; charset=utf-8");
                  str.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/xml; charset=utf-8"));
                  post.setEntity(str);
                  HttpResponse response = httpclient.execute(post);
                  HttpEntity entity = response.getEntity();
                  Returned = EntityUtils.toString(entity);
                  Toast.makeText(this, Returned, Toast.LENGTH_LONG).show();
                } catch ( IOException ioe ) {
                 ioe.printStackTrace();
                }
              }
    }
    

    thanks a lot for all your responses.

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

Sidebar

Related Questions

Please anyone help me. How to get HTTPs get/put/delete/post response in java.
Can anyone help? I have a PHP method that sends an http post: <?php
Hi can anyone help me, I want to be able to post tweets from
Can anyone help me to get good WordPress interview questions and answers. Any link
Please can anyone help me with this? I have 2 tables, location and tickets
Can anyone help me out of this problem, my javascript has an ajax GET
I have a problem with tomcat authentication. I want authenticate a user from a
Can anyone help? I have a change event on a textbox and a click
Can anyone help on how can I do to send the data from a
could anyone help me with this problem. What I have done is I wrote

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.