首页 > 解决方案 > 使用 Retrofit Get 方法的动态端点

问题描述

这是我的请求网址: http : //getpincodes.info/api.php?pincode=560054 其中 pincode 值是动态的。

这是我的代码:

public interface PincodeDetailsService 

@GET("")
Call<PincodeDetailsResponse> getPin(@Url String url);

}

apiUtils:

公共静态最终字符串 PINCODE_URL ="http://getpincodes.info/";

   public static PincodeDetailsService getPincodeDetailsService() {
    return RetrofitClientInstance.getRetrofitInstance(PINCODE_URL).create(PincodeDetailsService.class);
}

在进行网络通话时如何通过另一部分?有人可以帮我吗?

标签: androidgetretrofit

解决方案


签名应该是这样的:

@GET("api.php")
Call<PincodeDetailsResponse> getPin(@Query("pincode") int pincode);

然后简单地调用它使用

getPin(560054);

推荐阅读