我有一个用 Eclipse、Maven 和 Retrofit 1.3 制作的项目。我想迁移到 Android Studio,并且必须导入 gradle Retrofit 2.0。
在我进行了所有必要的更改以使其正常工作后,我得到了一些意想不到的东西。
我的改造构建器设置如下:
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://localhost:8080/openbravo/org.openbravo.service.json.jsonrest")
.client(httpClient)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson));
所以我的服务方法改为使用 <Call<List<T>>
而不仅仅是List<T>
当我执行 GET 方法登录时,我收到此响应错误:
Response{protocol=http/1.1, code=404, message=Not Found, url=http://localhost:8080/ADUser?_where=username%3D%27Openbravo%27}
但网址应该是:
http://localhost:8080/openbravo/org.openbravo.service.json.jsonrest/ADUser?_where=username%3D%27Openbravo%27
谁能告诉我为什么?我不知道发生了什么事...这在 1.3 上完美运行
最佳答案
您需要在基本网址末尾添加尾随/。否则改造会忽略它。请参阅https://github.com/square/retrofit/issues/1049 .
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://localhost:8080/openbravo/org.openbravo.service.json.jsonrest/")
.client(httpClient)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson));
关于android - Retrofit 2.0 中的网址错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33158617/