je suis en train d'envoyer la demande de poste à l'aide retrofit avec @FormUrlEncode, voici ma classe de serviceRénovation 2.3.0 toujours l'exécution onFailure
import com.dolphithronelab.siastar.response.AuthResponse;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
public interface SIAStarService {
@FormUrlEncoded
@POST("auth")
Call<AuthResponse>login(@Field("username") String username, @Field("password") String password);
}
voici ma retrofit classe client
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClient {
private static Retrofit retrofitClient =null;
public static Retrofit getClient(String apiserver){
if (retrofitClient == null){
retrofitClient = new Retrofit.Builder().baseUrl(apiserver).addConverterFactory(GsonConverterFactory.create()).build();
}
return retrofitClient;
}
}
et voici comment je communique avec le serveur api avec classe ApiKomunikator
public class ApiKomunikator {
public static final String BASE_URL = "http://10.44.7.118/siastar/public/api/";
public static SIAStarService getSIAStarService(){
return RetrofitClient.getClient(BASE_URL).create(SIAStarService.class);
}
}
et voici comment je l'appelle de la activité
siaStarService.login(mUsernameView.getText().toString(),mPasswordView.getText().toString())
.enqueue(new Callback<AuthResponse>() {
@Override
public void onResponse(Call<AuthResponse> call, Response<AuthResponse> response) {
if(response.isSuccessful())
{}
}
@Override
public void onFailure(Call<AuthResponse> call, Throwable t) {
Toast.makeText(LoginActivity.this, "Gagal koneksi ke server, periksa jaringan internet anda error: "+t.getMessage(), Toast.LENGTH_LONG).show();
showProgress(false);
}
});
lorsque je tente de publier des données via postier, il n'y a pas de problème, est-ce parce que je l'utilise IP statique ou quoi? et t.getMessage() toujours null
ajouter 't.printStackTrace();' et post la trace de la pile aussi. –