Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String main(String x, String y){
- if (android.os.Build.VERSION.SDK_INT > 9)
- {
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- }else{
- try{
- String username = x;
- String password = y;
- URL url = new URL(login_url);
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setDoInput(true);
- httpURLConnection.setDoOutput(true);
- OutputStream outputStream = httpURLConnection.getOutputStream();
- BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
- String post_data = URLEncoder.encode("username","UTF-8")+"="+URLEncoder.encode(username,"UTF-8")+"&"
- +URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8");
- bufferedWriter.write(post_data);
- bufferedWriter.flush();
- bufferedWriter.close();
- outputStream.close();
- // LÄSER FRÅN HEMSIDAN
- InputStream inputStream = httpURLConnection.getInputStream();
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
- String result="";
- String line="";
- while((line = bufferedReader.readLine()) != null){
- result += line;
- }
- //AVSLUTA CONNECTION
- bufferedReader.close();
- inputStream.close();
- httpURLConnection.disconnect();
- return result;
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- return null;
- }
- <uses-permission android:name="android.permission.INTERNET" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement