Hello! I have already read about a dozen guides on Retrofit2, but all of them explain only sending simple @GET @POST requests and I still don’t understand how to set the request I need, so I ask for help from knowledgeable people.

Actually such a request I want to ask using Retrofit2 " https://translate.yandex.net/api/v1.5/tr.json/translate?lang= " + lang + "&" + "text =" + text + "&" + API_KEY

// String lang specifies which language to translate // String text tex we are translating

As I understand it in the class where we create a Retrofit object, BASE_URL = " https://translate.yandex.net/ ";

In the interface

@GET("/api/v1.5/tr.json/translate?") Call<TranslationResponce>translateText(@Query("lang")String lang, @Query("text")String text, @Query("api_key")String apiKey); 

But apparently I do not understand correctly, since this query does not work. Please poke your nose, what am I doing wrong? Thank you in advance!

  • And what does the log write? - elik
  • @elik I haven’t figured out how to display the response log, but I know that in the if (response.isSuccessful ()) {block, the code does not work because my log is not displayed there. Error also does not display. - Mikhail
  • Well, ok, let's put the code in parts - elik
  • @elik something does not work out here to lay out, gives an error. Please look at the gita link - Mikhail
  • one
    @Mikhail, Remove the "key =" from the API_KEY line and @Query("api_key") with @Query("key") . Another parameter "lang" should contain the translation direction ('en-ru' for example) - woesss

1 answer 1

Remove the question mark from the @GET annotations at the end

  • Removed, unfortunately the result has not changed - Mikhail
  • Then try using Query annotations to replace Field. And above the GET method, specify FormUrlEncoded - pavel163
  • replaced, gives an error java.lang.IllegalArgumentException: FormUrlEncoded (for example, @POST). - Mikhail
  • Tried to change to @POST just in case, did not help - Mikhail
  • Give a link to the api method you are referring to - pavel163