Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

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();
like image 993
Prasanth Avatar asked Jul 15 '16 11:07

Prasanth


1 Answers

'?' 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);
like image 132
杨卢阳 Avatar answered Oct 19 '22 02:10

杨卢阳