Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected String doInBackground(String... params) {
- String username = params[0];
- String password = params[1];
- String loginURL = "http://10.0.3.2/carapp/login.php";
- String data = "";
- try {
- URL url = new URL(loginURL);
- String urlParams = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(username, "UTF-8") + "&" +
- URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8");
- System.out.println(urlParams);
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setDoInput(true);
- OutputStream os = httpURLConnection.getOutputStream();
- BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
- bufferedWriter.write(urlParams);
- bufferedWriter.flush();
- bufferedWriter.close();
- System.out.println(bufferedWriter);
- InputStream is = httpURLConnection.getInputStream();
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"));
- while ((tmp = is.read()) != -1) {
- data += (char) tmp;
- }
- is.close();
- httpURLConnection.disconnect();
- System.out.println("data data :: " + data);
- return data;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- System.out.println("data data :: " + data);
- return data;
- }
- <?php
- require "dbcon.php";
- if(!empty($_POST['username']) && !empty($_POST['password'])){
- $username = $_POST['username'];
- $password = $_POST['password'];
- $query = "SELECT forename, surname FROM users WHERE username = '$username' AND password = '$password' ";
- $result = mysqli_query($conn, $query);
- while($row = mysqli_fetch_assoc($result)){
- $response[] = $row;
- }
- if(!empty($response)){
- echo json_encode(array("final"=>$response));
- }
- else{
- echo "No records found ";
- }
- }
- else{
- echo "This file does not work";
- }
- ?>
- HttpPost postRequest = new HttpPost(params[0]);
- List<NameValuePair> postBody = new ArrayList<NameValuePair>(); // These are your post parameters
- postBody.add(new BasicNameValuePair("parameter1", "value");
- postBody.add(new BasicNameValuePair("parameter2", "value"));
- try {
- postRequest.setEntity(new UrlEncodedFormEntity(postBody));
- HttpResponse response = new DefaultHttpClient().execute(postRequest);
- Log.i(TAG, "Got response: " + EntityUtils.toString(response.getEntity()));
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- return null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement