Retrofit: Caused by: java.lang.IllegalArgumentException: baseUrl must end in /

Created on 5 Sep 2016  路  3Comments  路  Source: square/retrofit

Hi,

when I use GET method to request, always occurs a error"baseUrl must end in /", I don't know it's my fault or bug.

APIService
@GET Call<T> getDesignerList();

Java Code
`

url += "&sign=" + generateSign(url, null) + "/";

LogUtil.i("url===" + url);

Retrofit retrofit = new Retrofit.Builder()
      .addConverterFactory(GsonConverterFactory.create())
      .baseUrl(url)
      .build();

APIService apiService = retrofit.create(APIService.class);

Call<T> call = apiService.getDesignerList();

`

It is true when I print url to Log Window, and I can get data from browser and the url end is /.

PS: The format of my url:
http://192.168.1.2/travel/designerList?page=1&appver=&sysver=android&network=&res=&did=&mac=&token=&sign=xxx&mfr=SM-N9006/

Most helpful comment

You should not be setting a full endpoint URL as the base URL. I guess we should add another check for non-empty query params and non-empty fragments.

In this case, your base URL is http://192.168.1.2/ and the relative URL that should go inside of the @GET annotation is travel/designerList?page=1&appver=&sysver=android&network=&res=&did=&mac=&token=&sign=xxx&mfr=SM-N9006/

All 3 comments

You should not be setting a full endpoint URL as the base URL. I guess we should add another check for non-empty query params and non-empty fragments.

In this case, your base URL is http://192.168.1.2/ and the relative URL that should go inside of the @GET annotation is travel/designerList?page=1&appver=&sysver=android&network=&res=&did=&mac=&token=&sign=xxx&mfr=SM-N9006/

It resolved my problem. @JakeWharton thank you very much!

@JakeWharton It solved My problem Too, Thank You

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chriskessel picture chriskessel  路  3Comments

jpshelley picture jpshelley  路  4Comments

kkunsue picture kkunsue  路  3Comments

zheangrybear picture zheangrybear  路  3Comments

pankai picture pankai  路  3Comments