Android - No logro enviar el server key de mi app (android studio)

 
Vista:
sin imagen de perfil
Val: 2
Ha aumentado su posición en 34 puestos en Android (en relación al último mes)
Gráfica de Android

No logro enviar el server key de mi app (android studio)

Publicado por Eduardo (2 intervenciones) el 19/05/2020 06:39:39
Colegas, buen día

Estoy tratando de conectar a un api por medio de retrofit en la web para login, pero al ver el log, me arroja como si no detectará el server_key, tengo mi interfaz

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package Api;
 
 
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
 
public interface Api {
 
 
    @POST("auth")
    Call<Auth> login(@Body Auth auth);
 
 
 
}

***********************************************************************

tengo el api al cual me quiero conectar como clase
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Auth {
 
    private Integer user_id;
    private String server_key;
    private String username;
    private String password;
 
    public Auth(String server_key, String username, String password) {
        this.server_key = server_key;
        this.username = username;
        this.password = password;
    }
 
    public Integer getUser_id() {
        return user_id;
    }
***********************************************************
en el main creo el objeto de la clase Auth para enviar los parametros

1
2
3
4
5
String server_key = "42b4374f0b2cea90da2f30e6e0059af220426c7e-9a4727edf807c71a4adb585a67dfaa2d-18788129";
                    Auth auth = new Auth(
                            server_key,
                            email,
                            password);


los recolecto (el server_key es fijo, el email y contraseña los capturo del usuario)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
private void sendNetworkRequest(Auth auth)
    {
 
        //creamos Okhttp cliente
        OkHttpClient.Builder okhttpClientBuilder = new OkHttpClient.Builder();
        HttpLoggingInterceptor login = new HttpLoggingInterceptor();
        login.setLevel(HttpLoggingInterceptor.Level.BODY);
        okhttpClientBuilder.addInterceptor(login);
 
        //creamos la instancia de retrofit
        Retrofit.Builder builder = new Retrofit.Builder()
                .baseUrl("https://prueba/api/")
                .addConverterFactory(GsonConverterFactory.create())
                .client(okhttpClientBuilder.build());
 
        Retrofit retrofit = builder.build();
 
        //get cliente y call object for the reference
        Api api = retrofit.create(Api.class);
        Call<Auth> call = api.login(auth);
        call.enqueue(new Callback<Auth>() {
            @Override
            public void onResponse(Call<Auth> call, Response<Auth> response) {
 
 
                if (response.body() != null && response.isSuccessful())
                {
 
                    Toast.makeText(LoginActivity.this, "Exito: " + response.body().getUser_id(), Toast.LENGTH_SHORT).show();
                }
 
            }
 
            @Override
            public void onFailure(Call<Auth> call, Throwable t) {
                Toast.makeText(LoginActivity.this, "Algo salío mal :(" + t, Toast.LENGTH_SHORT).show();
            }
        });

al ver el log

2020-05-18 22:19:23.626 4633-4698/com.example.myapplication D/OkHttp: {"password":"contrasena","server_key":"42b4374f0b2cea90da2f30e6e0059af220426c7e-9a4727edf807c71a4adb585a67dfaa2d-18788129","username":"email"}
2020-05-18 22:19:24.416 4633-4698/com.example.myapplication D/OkHttp: "error_text": "Error: 404 POST (server_key) not specified, Admin Panel > API Settings > Manage API Server Key"

en postman si funciona el post
1
2
3
4
"api_status": 200,
    "timezone": "UTC",
    "access_token": "a8e869f60ac9744e0afadd87c911f1737c14ced8a7b0c16ad6f58f54c3d919b32383c89e636390515ba47c07b9b6a8f2718d94fa3f48fe9f",
    "user_id": "27"

¿que es lo que me esta fallando :( ?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de algoritmo
Val: 64
Bronce
Ha disminuido 1 puesto en Android (en relación al último mes)
Gráfica de Android

No logro enviar el server key de mi app (android studio)

Publicado por algoritmo (22 intervenciones) el 23/05/2020 15:41:56
Es este el dominio de servidor? https://prueba/api
Es probable que tengas que cambiar esa Base URL.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar