Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sleaq.php;
- import android.os.AsyncTask;
- import android.os.Debug;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.widget.Button;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Button button = (Button)findViewById(R.id.btnLogin);
- new Login().execute("http://www.sleaq.com/apps/416/login.php?username=penis2&password=password");
- }
- public class Login extends AsyncTask<String, String, String>
- {
- @Override
- protected String doInBackground(String... params)
- {
- HttpURLConnection conn = null;
- try
- {
- URL url;
- url = new URL(params[0]);
- conn = (HttpURLConnection) url.openConnection();
- if (conn.getResponseCode() == HttpURLConnection.HTTP_OK)
- {
- InputStream is = conn.getInputStream();
- Log.d("Message: ", convertStreamToString(is));
- }
- else
- {
- }
- return "Done";
- }
- catch (MalformedURLException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- finally
- {
- if (conn != null)
- {
- conn.disconnect();
- }
- }
- return null;
- }
- private String convertStreamToString(InputStream is)
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- StringBuilder sb = new StringBuilder();
- String line = null;
- try
- {
- while ((line = reader.readLine()) != null)
- {
- sb.append(line).append('\n');
- }
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement