0

This is my code below trying to create a login page using PHP, mysql and xampp server. I am having problem with BasicValueNamePair as it is deprecated. I dont know how to replace with new code. Any help please

URL url = new URL("http://10.0.3.2/android_api/check.php");
HttpURLConnection urlConnection =(HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.connect();

InputStream in = new BufferedInputStream(urlConnection.getInputStream());
String res = IOUtils.toString(in, "UTF-8");
System.out.println(res + " Blu bluh");

// make sure the url is correct.
//add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
// Always use the same variable name for posting i.e the android side variable name
// and php side variable name should be similar,
nameValuePairs.add(new BasicNameValuePair("Username",username.getText().toString().trim()));
//$Edittext_value = $_POST['Edittext_value'];
nameValuePairs.add(new BasicNameValuePair("Password",password.getText().toString().trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP Post Request
response=httpclient.execute(httppost);
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
  • this should help http://stackoverflow.com/questions/2793150/using-java-net-urlconnection-to-fire-and-handle-http-requests – pellucide Apr 09 '15 at 02:53

1 Answers1

0

HttpURLConnection is derived from URLConnection so you can use the addRequestProperty to include your name-value pairs.

urlConnection.addRequestProperty("Username",username.getText().toString());

See details here

Christian Abella
  • 5,747
  • 2
  • 30
  • 42