Guest User

Untitled

a guest
May 4th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. TextView mTextView;
  4. EditText link;
  5. EditText uname;
  6. EditText pswd;
  7.  
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.activity_main);
  12.  
  13. mTextView = (TextView) findViewById(R.id.showOutput);
  14. link = (EditText) findViewById(R.id.link);
  15. uname = (EditText) findViewById(R.id.uname);
  16. pswd = (EditText) findViewById(R.id.pswd);
  17. }
  18.  
  19. public void onPost(View view){
  20. try{
  21. URL url = new URL(link.getText().toString());
  22. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  23.  
  24. if(connection==null){
  25. return;
  26. }
  27.  
  28. String urlParameters = "username="+uname.getText().toString()+"&password="+pswd.getText().toString()+"&4Tredir="+"http://192.168.10.16:1000/login?0321cfcf14eae73e"+"&magic="+"052dcdc515e9e149";
  29. connection.setRequestMethod("POST");
  30. connection.setRequestProperty("USER-AGENT","Mozilla/5.0");
  31. connection.setRequestProperty("ACCEPT-LANGUAGE","en-US,en;0.5");
  32.  
  33. connection.setDoOutput(true);
  34. DataOutputStream dStream = new DataOutputStream(connection.getOutputStream());
  35.  
  36. if(dStream!=null) {
  37.  
  38. dStream.writeBytes(urlParameters);
  39. dStream.flush();
  40. dStream.close();
  41.  
  42.  
  43. int responseCode = connection.getResponseCode();
  44. String output = "Request URL " + url;
  45. output += System.getProperty("line.separator") + "Request Parameters" + urlParameters;
  46. output += System.getProperty("line.separator") + "Response code" + responseCode;
  47.  
  48. BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  49. String line = "";
  50. StringBuilder responseOutput = new StringBuilder();
  51.  
  52. while ((line = br.readLine()) != null) {
  53. responseOutput.append(line);
  54. }
  55. br.close();
  56.  
  57. output += System.getProperty("line.separator") + responseOutput.toString();
  58. mTextView.setText(output);
  59.  
  60. }
  61. } catch (MalformedURLException e) {
  62. e.printStackTrace();
  63. } catch (IOException e) {
  64. e.printStackTrace();
  65. } catch (Exception e){
  66. e.printStackTrace();
  67. }
  68. }
  69.  
  70. public void Login(View view){
  71. // Instantiate the RequestQueue.
  72. RequestQueue queue = Volley.newRequestQueue(this);
  73. String url =link.getText().toString();
  74.  
  75. mTextView.setText("CHECKING.....!!!");
  76.  
  77. // Request a string response from the provided URL.
  78. StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
  79. @Override
  80. public void onResponse(String response) {
  81. mTextView.setText(response.toString());
  82. }
  83. }, new Response.ErrorListener() {
  84. @Override
  85. public void onErrorResponse(VolleyError error) {
  86. mTextView.setText("That didn't work!!! "+error.getMessage());
  87. }
  88. })
  89. {
  90. @Override
  91. protected Map<String, String> getParams() {
  92. Map<String, String> params = new HashMap<String, String>();
  93. params.put("username",uname.getText().toString());
  94. params.put("password",pswd.getText().toString());
  95. params.put("4Tredir","http://192.168.10.16:1000/login?0321cfcf14eae73e");
  96. params.put("magic","052dcdc515e9e149");
  97. params.put("","");
  98. //params.put("submit","SUBMIT");
  99.  
  100. return params;
  101. }
  102.  
  103. @Override
  104. public Map<String, String> getHeaders() throws AuthFailureError {
  105. Map<String, String> params = new HashMap<String, String>();
  106. params.put("Content-Type", "application/x-www-form-urlencoded");
  107. return params;
  108. }
  109. };
  110.  
  111. // Add the request to the RequestQueue.
  112. queue.add(stringRequest);
  113. }
Add Comment
Please, Sign In to add comment