J'ai une URL par exemple:Rénovation - valeurs d'URL Passe dynamique - méthode GET
https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVinValues/KMHDC8AEXAU084769?format=JSON
Ici, je veux changer KMHDC8AEXAU084769?format=JSON
cette partie dynamique
Comment faire avec Retrofit2.
J'ai essayé comme:
@FormUrlEncoded
@GET("{input}")
Call<Result> getVin(@Path("input") String input, @Field("format") String format);
Mais @FormUrlEncoded
est prend en charge que pour POST pas GET.
C'est la façon dont je l'appelle:
ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
Call<Result> call = apiService.getVin(vin, "JSON");
call.enqueue(new Callback<Result>() {
@Override
public void onResponse(Call<Result> call, Response<Result> response) {
Result result = response.body();
Log.e("Result: ", "" + response.body());
Gson gson = new Gson();
String json = gson.toJson(result);
responseTV.setText("" + json);
}
@Override
public void onFailure(Call<Result> call, Throwable t) {
// Log error here since request failed
Log.e("MainActivity", t.toString());
Toast.makeText(MainActivity.this, "Try later", Toast.LENGTH_SHORT).show();
}
});
Merci d'avoir essayé, mais cela ne fonctionne pas –
Bien sûr, vous devez adapter la structure url dans l'annotation GET pour vos buts –