Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

android - java.lang.IllegalArgumentException: baseUrl must end in / while using retrofit 2.1.0 for GET method

I am using Retrofit2 for API parsing.

While using retrofit1.9.0 both post and get methods work properly. But using retrofit 2.1.0, in the get method, there is an error:

java.lang.IllegalArgumentException: baseUrl must end in /

I have checked my code and there is no problem, it's working for the post method.

    Retrofit retrofit= new Retrofit.Builder() 
                        .baseUrl("sample.com/ecomtest/index.php?route=api/") 
                        .addConverterFactory(GsonConverterFactory.create())
                        .build();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

'?' can not in baseUrl, you should move it to API interface. like this.

The full url :https://free-api.heweather.com/v5/now? city=yourcity&key=yourkey

so, baseUrl = "https://free-api.heweather.com/v5/"

and the API interface

@GET("now?")
Observable<HeWeather5> getNowWeather(@Query("city") String city,@Query("key") String key);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...