gpt4 book ai didi

android - Retrofit 2.0 中的错误网址

转载 作者:行者123 更新时间:2023-11-29 00:06:58 27 4
gpt4 key购买 nike

我有一个使用 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}

但是 url 应该是:

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com