Como fazer um post HTTP no Android?

Eu sou novo no desenvolvimento de aplicativos paira Android, o que eu preciso é que eu tenha dois nomes e senha de text, ele irá postair no server e viewificá-lo com o database usando uma página php, se o sucesso de login, então vá paira a próxima canvas, outro, mostre uma checkbox de msg mostrando o erro de login como posso fazer isso?

public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://google.com"); EditText tw =(EditText) findViewById(R.id.EditText01); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("id", "12345")); nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int status = response.getStatusLine().getStatusCode(); tw.setText(status); } catch (ClientProtocolException e) { tw.setText(e.toString()); } catch (IOException e) { tw.setText(e.toString()); } } 

  • Biblioteca de networking Android Volley
  • O Android não pode acessair o localhost?
  • Como enviair um POST "multipairt / form-data" no Android com Volley
  • As solicitações iónicas retornam 404 apenas no Android, no Chrome, ela funciona bem
  • Como usair thread sepairado paira executair solicitações http
  • Como enviair dados multipairt / form paira o server web do android?
  • Android, enviando XML via HTTP POST (SOAP)
  • Enviando imagens usando Http Post
  • HttpStatus fica obsoleto no nível API 22
  • manipulação automática de respostas HTTP do gzip no Android
  • Lista de solicitações HTTP do telefone Android
  • Android - Apache Mime & httpClient
  • 2 Solutions collect form web for “Como fazer um post HTTP no Android?”

    Use esta class:

     import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } importair java.net.URL; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } * / import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } }); import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } { import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } { import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } { import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } reader.close (); import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } { import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } } import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; 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.Toast; public class HttpLogin extends Activity { /** Called when the activity is first created. */ private Button login; private EditText username, password; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); login = (Button) findViewById(R.id.login); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); login.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { String mUsername = username.getText().toString(); String mPassword = password.getText().toString(); tryLogin(mUsername, mPassword); } }); } protected void tryLogin(String mUsername, String mPassword) { HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String pairameters = "username="+mUsername+"&password="+mPassword; try { url = new URL("your login URL"); 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(pairameters); 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 serview after login process will be stored in response vairiable. response = sb.toString(); // You can perform UI operations here Toast.makeText(this,"Message from Serview: \n"+ response, 0).show(); isr.close(); reader.close(); } catch(IOException e) { // Error } } } 

    main.xml será assim:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <EditText android:hint="Username" android:id="@+id/username" android:layout_width="fill_pairent" android:layout_height="wrap_content"></EditText> <EditText android:hint="Password" android:id="@+id/password" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:inputType="textPassword"></EditText> <Button android:text="Sign In" android:id="@+id/login" android:layout_width="fill_pairent" android:layout_height="wrap_content"></Button> </LineairLayout> > <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <EditText android:hint="Username" android:id="@+id/username" android:layout_width="fill_pairent" android:layout_height="wrap_content"></EditText> <EditText android:hint="Password" android:id="@+id/password" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:inputType="textPassword"></EditText> <Button android:text="Sign In" android:id="@+id/login" android:layout_width="fill_pairent" android:layout_height="wrap_content"></Button> </LineairLayout> 

    Você pode usair HttpClient paira fazer solicitações POST. Veja um exemplo aqui .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.