My code
public interface ApiInterface
{
@GET("convert?q=USD_{currency}&compact=ultra&apiKey="+API_KEY)
Call<Currency> getRates(@Path("currency") String currency );
}
But I am getting the following Error:
java.lang.IllegalArgumentException: URL query string "q=USD_{currency}&compact=ultra&apiKey=9b1166408fb8799dee9e" must not have replace block. For dynamic query parameters use @Query.
make your interface like this:
@GET("convert")
Call<Currency> getRates(@Query("q") String query, @Query("compact") String compact, @Query("apiKey") String apiKey);
You can call it like this way:
String mCurrency="$";
Call<Currency> call = mApiInterface.getRates("USD_"+mCurrency, "ultra", API_KEY);
You need to put your query parameters inside of the interface like this:
@GET("convert")
Call<Currency> getRates(@Query("q") String currency, @Query("compact") String compact, @Query("apiKey") String apiKey);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.