I just used the function below when I ran into this problem. but I was in a hurry, and I believe that I should use another, and I used "retrofit2: retrofit: 2.0.2"
public static Retrofit getClient(String baseURL) { if (retrofit == null) { retrofit = new Retrofit.Builder() .baseUrl(baseURL) .addConverterFactory(GsonConverterFactory.create()) .build(); } else { if (!retrofit.baseUrl().equals(baseURL)) { retrofit = new Retrofit.Builder() .baseUrl(baseURL) .addConverterFactory(GsonConverterFactory.create()) .build(); } } return retrofit; }
[ Update ] I found this link explaining @Url, which can be sent as a parameter, and I believe that it is more professional than my old solution. Please find below script:
interface APIService{ @POST Call<AuthenticationResponse> login(@Url String loginUrl,[other parameters]) }
And below is a method in a class that provides a modified object
public static Retrofit getClient() { if (retrofit==null) { retrofit = new Retrofit.Builder() .baseUrl("http://baseurl.com")
Then you can call the method as shown below:
APIInterface apiInterface = ApiClient.getClient2().create(ApiInterface.class); apiInterface.login("http://tempURL.com").enqueue(......);
Vattic
source share