Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- TextView mTextView;
- EditText link;
- EditText uname;
- EditText pswd;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mTextView = (TextView) findViewById(R.id.showOutput);
- link = (EditText) findViewById(R.id.link);
- uname = (EditText) findViewById(R.id.uname);
- pswd = (EditText) findViewById(R.id.pswd);
- }
- public void onPost(View view){
- try{
- URL url = new URL(link.getText().toString());
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- if(connection==null){
- return;
- }
- String urlParameters = "username="+uname.getText().toString()+"&password="+pswd.getText().toString()+"&4Tredir="+"http://192.168.10.16:1000/login?0321cfcf14eae73e"+"&magic="+"052dcdc515e9e149";
- connection.setRequestMethod("POST");
- connection.setRequestProperty("USER-AGENT","Mozilla/5.0");
- connection.setRequestProperty("ACCEPT-LANGUAGE","en-US,en;0.5");
- connection.setDoOutput(true);
- DataOutputStream dStream = new DataOutputStream(connection.getOutputStream());
- if(dStream!=null) {
- dStream.writeBytes(urlParameters);
- dStream.flush();
- dStream.close();
- int responseCode = connection.getResponseCode();
- String output = "Request URL " + url;
- output += System.getProperty("line.separator") + "Request Parameters" + urlParameters;
- output += System.getProperty("line.separator") + "Response code" + responseCode;
- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String line = "";
- StringBuilder responseOutput = new StringBuilder();
- while ((line = br.readLine()) != null) {
- responseOutput.append(line);
- }
- br.close();
- output += System.getProperty("line.separator") + responseOutput.toString();
- mTextView.setText(output);
- }
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (Exception e){
- e.printStackTrace();
- }
- }
- public void Login(View view){
- // Instantiate the RequestQueue.
- RequestQueue queue = Volley.newRequestQueue(this);
- String url =link.getText().toString();
- mTextView.setText("CHECKING.....!!!");
- // Request a string response from the provided URL.
- StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- mTextView.setText(response.toString());
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- mTextView.setText("That didn't work!!! "+error.getMessage());
- }
- })
- {
- @Override
- protected Map<String, String> getParams() {
- Map<String, String> params = new HashMap<String, String>();
- params.put("username",uname.getText().toString());
- params.put("password",pswd.getText().toString());
- params.put("4Tredir","http://192.168.10.16:1000/login?0321cfcf14eae73e");
- params.put("magic","052dcdc515e9e149");
- params.put("","");
- //params.put("submit","SUBMIT");
- return params;
- }
- @Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- Map<String, String> params = new HashMap<String, String>();
- params.put("Content-Type", "application/x-www-form-urlencoded");
- return params;
- }
- };
- // Add the request to the RequestQueue.
- queue.add(stringRequest);
- }
Add Comment
Please, Sign In to add comment