为什么 Retrofit @Path 没有被替换?
Why Retrofit @Path is not replacing?
我有一个大项目正在使用 Retrofit 2.0 beta2,但是@Path 似乎以某种方式损坏了。
这是服务器端收到请求时的日志:/group/%7Bid%7D/users
“{}”被识别为编码值,而不是将其替换为实际值。
我尝试创建一个测试项目,它似乎工作正常,但是当我在大项目中尝试相同的代码时,它崩溃了!可能是什么原因? proguarding 是这里的问题吗?
这是我测试过的简单界面
@GET("/group/{id}/users")
Call<Object> groupList(@Path("id") int groupId);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://1.1.1.1:5050")
.addConverterFactory(GsonConverterFactory.create())
.build();
RetrofitConfigurationService2 service = retrofit.create(RetrofitConfigurationService2.class);
service.groupList(12).enqueue(new Callback<Object>() {
@Override
public void onResponse(Response<Object> response, Retrofit retrofit) {
}
@Override
public void onFailure(Throwable t) {
}
});
谢谢!
现在尝试阅读此博客:http://inthecheesefactory.com/blog/retrofit-2.0/en
Retrofit 2.0 comes with new URL resolving concept. Base URL and @Url
have not just simply been combined together but have been resolved the
same way as what does instead.
作者总结:
Base URL: always ends with /
@Url: DO NOT start with /
如果您在项目中使用 Proguard,请将以下行添加到您的配置中:
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
答案是 -keep interface com.yourretrofitinterface.** { *; }
在混淆文件中。
我遇到了完全相同的问题。
一个更通用的解决方案是将以下内容添加到您的混淆器规则中。
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
关于复古的完整规则:
-keepattributes Signature
-keepattributes Exceptions
-dontnote okhttp3.**, retrofit2.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
我有一个大项目正在使用 Retrofit 2.0 beta2,但是@Path 似乎以某种方式损坏了。
这是服务器端收到请求时的日志:/group/%7Bid%7D/users “{}”被识别为编码值,而不是将其替换为实际值。
我尝试创建一个测试项目,它似乎工作正常,但是当我在大项目中尝试相同的代码时,它崩溃了!可能是什么原因? proguarding 是这里的问题吗?
这是我测试过的简单界面
@GET("/group/{id}/users")
Call<Object> groupList(@Path("id") int groupId);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://1.1.1.1:5050")
.addConverterFactory(GsonConverterFactory.create())
.build();
RetrofitConfigurationService2 service = retrofit.create(RetrofitConfigurationService2.class);
service.groupList(12).enqueue(new Callback<Object>() {
@Override
public void onResponse(Response<Object> response, Retrofit retrofit) {
}
@Override
public void onFailure(Throwable t) {
}
});
谢谢!
现在尝试阅读此博客:http://inthecheesefactory.com/blog/retrofit-2.0/en
Retrofit 2.0 comes with new URL resolving concept. Base URL and @Url have not just simply been combined together but have been resolved the same way as what does instead.
作者总结:
Base URL: always ends with /
@Url: DO NOT start with /
如果您在项目中使用 Proguard,请将以下行添加到您的配置中:
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
答案是 -keep interface com.yourretrofitinterface.** { *; } 在混淆文件中。
我遇到了完全相同的问题。 一个更通用的解决方案是将以下内容添加到您的混淆器规则中。
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
关于复古的完整规则:
-keepattributes Signature
-keepattributes Exceptions
-dontnote okhttp3.**, retrofit2.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}