Guest User

Untitled

a guest
Apr 10th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. public class MainActivity2 extends MainActivity {
  2.  
  3. EditText bQ, bR;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main2);
  9.  
  10. bQ = (EditText) findViewById(R.id.username);
  11. bR = (EditText) findViewById(R.id.password);
  12.  
  13. public void insertIntoDatabase() {
  14. final String username = bQ.getText().toString();
  15. final String password = bR.getText().toString();
  16.  
  17. class SendPostReqAsyncTask extends AsyncTask<String, Void, String> {
  18. @Override
  19. protected String doInBackground(String... params) {
  20. String paramUsername = params[0];
  21. String paramPassword = params[1];
  22.  
  23. try {
  24. URL url = new URL("http://passwds.esy.es/upload.php");
  25. HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  26. httpURLConnection.setRequestMethod("POST");
  27. httpURLConnection.setDoOutput(true);
  28. httpURLConnection.setDoInput(true);
  29. //OutputStream outputStream = httpURLConnection.getOutputStream();
  30. BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(httpURLConnection.getOutputStream(), "UTF-8"));
  31. String userPass = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(paramUsername, "UTF-8") + "&"
  32. + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(paramPassword, "UTF-8");
  33. bufferedWriter.write(userPass);
  34. bufferedWriter.flush();
  35. bufferedWriter.close();
  36.  
  37. InputStream inputStream = httpURLConnection.getInputStream();
  38. inputStream.close();
  39. httpURLConnection.disconnect();
  40.  
  41. } catch (IOException e) {
  42. e.printStackTrace();
  43. }
  44.  
  45. return "success";
  46. }
  47.  
  48. @Override
  49. protected void onPostExecute(String result) {
  50. super.onPostExecute(result);
  51. Log.v("Result:", result);
  52. }
  53. }
  54. SendPostReqAsyncTask sendPostReqAsyncTask = new SendPostReqAsyncTask();
  55. sendPostReqAsyncTask.execute(username, password);
  56. }
  57. public void submit(View view) {
  58. insertIntoDatabase();
  59. }
  60.  
  61.  
  62. }
Add Comment
Please, Sign In to add comment