Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

public void Login(View view) {

StringRequest postRequest = new StringRequest(Request.Method.POST, url, new


Response.Listener<String>())
String URL = "http://localhost:5180/api/Login";
String Usuario = usuario.getText().toString();
String Password = password1.getText().toString();
new Thread(new Runnable() {
@Override
public void run() {
RequestBody postBody = new FormBody.Builder()
.add("Email", Usuario)
.add("Password",Password)
.build();

Request request = new Request.Builder()


.url(URL)
.post(postBody)
.build();

OkHttpClient client = new OkHttpClient();


Call call = client.newCall(request);

Response response = null;


final MediaType JSON = MediaType.get("");

try {
response = call.execute();
String serverResponse = response.body().toString();
runOnUiThread(new Runnable() {
@Override
public void run() {
if (serverResponse.equals("Data Found")){
Intent intent = new
Intent(getApplicationContext(),MainActivity2.class);
startActivity(intent);
}
}
});
}catch (IOException e) {
e.printStackTrace();
}

}
}).start();
}

codigo anterior de conexion anterior a java

Librerias papra okhttp


implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.12.0"))
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")

You might also like