Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. @Override
  2. protected String doInBackground(String... params) {
  3. String username = params[0];
  4. String password = params[1];
  5. String loginURL = "http://10.0.3.2/carapp/login.php";
  6. String data = "";
  7.  
  8. try {
  9. URL url = new URL(loginURL);
  10. String urlParams = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(username, "UTF-8") + "&" +
  11. URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8");
  12. System.out.println(urlParams);
  13. HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  14. httpURLConnection.setRequestMethod("POST");
  15. httpURLConnection.setDoOutput(true);
  16. httpURLConnection.setDoInput(true);
  17. OutputStream os = httpURLConnection.getOutputStream();
  18. BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
  19. bufferedWriter.write(urlParams);
  20. bufferedWriter.flush();
  21. bufferedWriter.close();
  22. System.out.println(bufferedWriter);
  23.  
  24. InputStream is = httpURLConnection.getInputStream();
  25. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"));
  26. while ((tmp = is.read()) != -1) {
  27. data += (char) tmp;
  28. }
  29.  
  30. is.close();
  31. httpURLConnection.disconnect();
  32. System.out.println("data data :: " + data);
  33. return data;
  34.  
  35.  
  36. } catch (MalformedURLException e) {
  37. e.printStackTrace();
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. System.out.println("data data :: " + data);
  42. return data;
  43. }
  44.  
  45. <?php
  46. require "dbcon.php";
  47. if(!empty($_POST['username']) && !empty($_POST['password'])){
  48. $username = $_POST['username'];
  49. $password = $_POST['password'];
  50.  
  51. $query = "SELECT forename, surname FROM users WHERE username = '$username' AND password = '$password' ";
  52.  
  53. $result = mysqli_query($conn, $query);
  54.  
  55. while($row = mysqli_fetch_assoc($result)){
  56. $response[] = $row;
  57. }
  58.  
  59. if(!empty($response)){
  60. echo json_encode(array("final"=>$response));
  61. }
  62. else{
  63. echo "No records found ";
  64. }
  65. }
  66. else{
  67. echo "This file does not work";
  68. }
  69.  
  70. ?>
  71.  
  72. HttpPost postRequest = new HttpPost(params[0]);
  73. List<NameValuePair> postBody = new ArrayList<NameValuePair>(); // These are your post parameters
  74. postBody.add(new BasicNameValuePair("parameter1", "value");
  75. postBody.add(new BasicNameValuePair("parameter2", "value"));
  76. try {
  77. postRequest.setEntity(new UrlEncodedFormEntity(postBody));
  78. HttpResponse response = new DefaultHttpClient().execute(postRequest);
  79.  
  80. Log.i(TAG, "Got response: " + EntityUtils.toString(response.getEntity()));
  81. } catch (IOException ex) {
  82. ex.printStackTrace();
  83. }
  84. return null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement