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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:44:28+00:00 2026-05-23T10:44:28+00:00

I’m trying to make a login to my website via an Android app. For

  • 0

I’m trying to make a login to my website via an Android app.
For some reason something always goes wrong.

Here’s my site login structure:

  • Login.php – the login form (username
    & password)
  • Auth.php – login authentication page
    (gets the username & password from
    page – login.php (POST method))

I already have to interface with Username & Password (EditText both)

What is the method to make a login via android app?

here’s my current login method

private void login() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();

    /* login.php returns true if username and password is equal to saranga */
    HttpPost httppost = new HttpPost("my auth.php file url");

    try {
        // Add user name and password
        String username = this.usernameField.getText();
        String password = this.passwordField.getText();

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("username", username));
        nameValuePairs.add(new BasicNameValuePair("password", password));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));


        HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Thanks

  • 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-23T10:44:29+00:00Added an answer on May 23, 2026 at 10:44 am

    A few days ago I had some similar problems.
    You can have a look at the following code.

    public class API {
    // constants
    private final String TAG = "API";
    private final String API_URL_SECURE = "your url";
    private final String API_URL = "your url";
    private static API instance;    
    
    // data
    private HttpClient client;  
    private ClientConnectionManager cm;
    private HttpPost post;    
    private HttpContext httpContext;
    private HttpParams params;
    
    private API() {
    
        params      = new BasicHttpParams();
        httpContext = new BasicHttpContext();
        ConnManagerParams.setMaxTotalConnections(params, 300);
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);                          
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register( new Scheme("http", PlainSocketFactory.getSocketFactory(), 80) );
    
        cm          = new ThreadSafeClientConnManager(params, schemeRegistry);
        client      = new DefaultHttpClient(cm, params);                        
    
    }
    
    
    public static API getInstance(){
        if(instance == null){
            instance = new API();
            return instance;
        }
        else
            return instance;
    }
    
    private static String getCredentials(String userName, String password){     
        return Base64.encodeBytes((userName + ":" + password).getBytes());
    }
    
    private String makeRequest(String url, JSONObject json, String userName, String userPassword) {
    
        try {          
            post            = new HttpPost(url);                                           
            StringEntity en = new StringEntity(json.toString());    
    
            post.setEntity(en);
            post.setHeader("Accept", "application/json");
            post.setHeader("Content-type", "application/json");
    
            if(userName != null && userPassword != null)
                post.addHeader("Authorization","Basic "+ getCredentials(userName, userPassword));           
    
            HttpResponse responsePOST = client.execute(post, httpContext);  
            HttpEntity   resEntity    = responsePOST.getEntity();
    
            return EntityUtils.toString(resEntity);
    
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    
    public synchronized String login(String user_name, String user_password){
        JSONObject json     = new JSONObject();
        JSONObject params   = new JSONObject();
    
        try {
            json.put("method", "log_in_user");
            params.put("user_name", user_name);
            params.put("user_pass", user_password);
            json.put("params", params);
            String result = makeRequest(API_URL_SECURE, json, user_name, user_password);
            return result;          
        }
        catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.