Android : 改造和使用动态 URLS
Android : Retrofit and using dynamic URLS
早上好。我是 Retrofit 的新手,接手了另一个项目。我们需要与 API 对话,它在每次调用时使用 url 中的代码
例如 http://www.example.com/CODE/review
我想我会尝试显而易见的,但 Retrofit 抱怨 属性值必须是常量
public interface ApiService{
public static final String ref = getRefCode();
//TODO: Use ref number to identify users
@Headers({
"Accept: application/json",
"Content-Type: application/json"})
@GET("/" + ref + "/RepairStatus")
void getRepairStatus(@Header("If-None-Match") String ifNoneMatch, RestCallback<RepairStatusResponse> callback);
@Headers({
"Accept: application/json",
"Content-Type: application/json"})
@POST("/" + ref + "/Review")
void postReview(@Body ReviewRequest reviewRequest);
}
抱歉,如果我遗漏了明显的:)
你不做这样的事情吗:
@GET("/group/{id}/users") List<User> groupList(@Path("id") int groupId);
早上好。我是 Retrofit 的新手,接手了另一个项目。我们需要与 API 对话,它在每次调用时使用 url 中的代码 例如 http://www.example.com/CODE/review
我想我会尝试显而易见的,但 Retrofit 抱怨 属性值必须是常量
public interface ApiService{
public static final String ref = getRefCode();
//TODO: Use ref number to identify users
@Headers({
"Accept: application/json",
"Content-Type: application/json"})
@GET("/" + ref + "/RepairStatus")
void getRepairStatus(@Header("If-None-Match") String ifNoneMatch, RestCallback<RepairStatusResponse> callback);
@Headers({
"Accept: application/json",
"Content-Type: application/json"})
@POST("/" + ref + "/Review")
void postReview(@Body ReviewRequest reviewRequest);
}
抱歉,如果我遗漏了明显的:)
你不做这样的事情吗:
@GET("/group/{id}/users") List<User> groupList(@Path("id") int groupId);