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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:55:19+00:00 2026-05-26T20:55:19+00:00

Hi I’m starting with android developing, and I have to create a login form

  • 0

Hi I’m starting with android developing, and I have to create a login form wich clicking a button, it’ll send this: http://www.mypage.com/?U=USUARI&K=PASSWORD.
Searching in here I’ve founded a method that Vikas Patidar uploaded nad I’ve tryed to modify it to my needs. But I think there’s something wrong because it doesn’t works.
Can you tell me where I am mistaking please?

This is the code
`

public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText U, K;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    login = (Button) findViewById(R.id.login);
    U = (EditText) findViewById(R.id.U);
    K = (EditText) findViewById(R.id.K);

    login.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            String   mUsername = U.getText().toString();
            String  mPassword = K.getText().toString();

            tryLogin(mUsername, mPassword);
        }
    });
}

protected void tryLogin(String mUsername, String mPassword)
{           
    HttpURLConnection connection;
   OutputStreamWriter request = null;

        URL url = null;   
        String response = null;         
        String parameters = "U="+mUsername+"&K="+mPassword;   

        try
        {
            url = new URL("http://http://www.mypage.com/content/frmLogin.aspx");
            connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            connection.setRequestMethod("POST");    

            request = new OutputStreamWriter(connection.getOutputStream());
            request.write(parameters);
            request.flush();
            request.close();            
            String line = "";               
            InputStreamReader isr = new InputStreamReader(connection.getInputStream());
            BufferedReader reader = new BufferedReader(isr);
            StringBuilder sb = new StringBuilder();
            while ((line = reader.readLine()) != null)
            {
                sb.append(line + "\n");
            }
            // Response from server after login process will be stored in response variable.                
            response = sb.toString();
            // You can perform UI operations here
            Toast.makeText(this,"Message from Server: \n"+ response, 0).show();             
            isr.close();
            reader.close();

        }
        catch(IOException e)
        {
            // Error
        }
}
´

and the xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
  >
<EditText 
android:hint="Username" 
android:id="@+id/U" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</EditText>

<EditText 
android:hint="Password" 
android:id="@+id/K" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:inputType="textPassword">
</EditText>

<Button 
android:text="Iniciar Sessió" 
android:id="@+id/login" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</Button>
</LinearLayout>

Now I’m trying with HTTP GET method and I got this

packge com.android.v3;

import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class v3act extends Activity {
    TextView Tname,Tpass;
    EditText Ename,Epass;
    Button btnCreate;
     String n=null;
     String contentOfMyInputStream1;
     String output = null;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnCreate = (Button) findViewById(R.id.btnGen);
        Tname = (TextView) findViewById(R.id.txtName);
        Ename = (EditText) findViewById(R.id.editName);
        Tpass = (TextView) findViewById(R.id.txtPass);
        Epass = (EditText) findViewById(R.id.editPass);




        btnCreate.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            Tname.setText("");
            // Thread thread = new Thread();
             String st1;

             st1=Ename.getText().toString();
            //thread.start();

             Tpass.setText("");
             // Thread thread = new Thread();
              String st2;

              st2=Epass.getText().toString();
             //thread.start();

            try {
                 output ="http://www.mypage.com/?U="+st1+"K="+st2;
                downloadUrl(output);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (output != null) 
            {
                Tname.setText(output);
            }


            }
            });


    }

    public String downloadUrl(String url) throws  IOException{
        HttpClient httpclient = new DefaultHttpClient();  
        HttpRequestBase httpRequest = null;
        HttpResponse httpResponse = null;
        InputStream inputStream = null;
        String response = "";
        StringBuffer buffer = new StringBuffer();

        httpRequest = new HttpGet(url); 

        httpResponse = httpclient.execute(httpRequest);
        inputStream = httpResponse.getEntity().getContent();
        int contentLength = (int) httpResponse.getEntity().getContentLength();
        if (contentLength < 0){
           // Log.e(TAG, "The HTTP response is too long.");
        }
        byte[] data = "8" byte[256];
        int len = 0;
        while (-1 != (len = inputStream.read(data)) )
        {
            buffer.append(new String(data, 0, len));
        }

        inputStream.close();

        response = buffer.toString();

        return response;

    }


}

but I have some mistake on the line where goes:

byte[] data = "8" byte[256];

It says: ‘Syntax error on token “byte”, delete this token’
And if I delete that, I get more errors in reacton.

What should I do?

  • 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-26T20:55:19+00:00Added an answer on May 26, 2026 at 8:55 pm

    Delete

    The conn.setRequestMethod("POST");
    

    and then the conn.setDoOutput(true); already means you are using POST communication.

    next.

            request.write(parameters);
            request.flush();
            request.close();
    

    change it to

            request.write(parameters.getBytes());
            request.flush();
            //request.close();//it is closing prematurly so you will definitely not get any response at all... 
    

    try these out and let me know if it turns out okey…

    if you want to check out try this example which looks almost similar to your conditions…

    Might be that will help tooo…. respond.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
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
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.