Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends Activity {
- private final OkHttpClient client = new OkHttpClient();
- private String usernameValue;
- private String passwordValue;
- private String databaseValue;
- @InjectView(R.id.usernameField) EditText usernameContainer;
- @InjectView(R.id.passwordField) EditText passwordContainer;
- @InjectView(R.id.databaseField) EditText databaseContainer;
- @InjectView(R.id.loginButton) Button loginButton;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ButterKnife.inject(this);
- loginButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- try {
- runLogin();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public void runLogin() throws Exception {
- usernameValue = usernameContainer.getText().toString();
- passwordValue = passwordContainer.getText().toString();
- databaseValue = databaseContainer.getText().toString();
- RequestBody formBody = new FormEncodingBuilder()
- .add("Username", usernameValue)
- .add("Password", passwordValue)
- .add("Database", databaseValue)
- .build();
- Request request = new Request.Builder()
- .url("http://10.0.0.2/newnew/login.php")
- .post(formBody)
- .build();
- Response response = client.newCall(request).execute();
- if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
- if(response.isSuccessful())
- {
- Toast.makeText(getApplicationContext(), "Connected successfully",
- Toast.LENGTH_LONG).show();
- }
- System.out.println(response.body().string());
- // Log.i("LOGI", response.body().string());
- }
Advertisement
Add Comment
Please, Sign In to add comment