我正在使用 Retrofit2 进行 API 解析。
在使用 retrofit1.9.0
,post 和 get 方法都可以正常工作。但是使用 retrofit 2.1.0
,在get方法中,出现错误:
java.lang.IllegalArgumentException: baseUrl 必须以 / 结尾
我已经检查了我的代码,没有问题,它正在为 post 方法工作。
Retrofit retrofit= new Retrofit.Builder()
.baseUrl("sample.com/ecomtest/index.php?route=api/")
.addConverterFactory(GsonConverterFactory.create())
.build();
原文由 Prasanth 发布,翻译遵循 CC BY-SA 4.0 许可协议
“?”不能在baseUrl中,你应该把它移到API接口。像这样。
完整网址:
https://free-api.heweather.com/v5/now? city=yourcity&key=yourkey
所以,
baseUrl = "https://free-api.heweather.com/v5/"
和API接口