[英]How to Retrofit call this API GET method
I passing TranID from using GET method.我使用 GET 方法传递 TranID。 I have a problem for API call, please give some example API calls.
我对 API 调用有疑问,请举例 API 调用。 http://testing.ppms.co.in/Redipae/Payout/Approvemercsmspwalink?TranID=20
http://testing.ppms.co.in/Redipae/Payout/Approvemercsmspwalink?TranID=20
{ "result": true, "newurl": "/Redipae/Payout/mercpushsmslink" } {“结果”:真,“newurl”:“/Redipae/Payout/mercpushsmslink”}
Retrofit client defined below Retrofit 客户端定义如下
public class API {
public static Retrofit getClient() {
return new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(" http://testing.ppms.co.in/").client(new OkHttpClient.Builder().connectTimeout(120, TimeUnit.SECONDS).writeTimeout(120, TimeUnit.SECONDS).readTimeout(120, TimeUnit.SECONDS).build();
}
}
You need an interface for the API您需要 API 的接口
public interface RequestServer {
@GET("Redipae/Payout/Approvemercsmspwalink")
Call<ResponseBody> getResponse(@Query("TranID") int transId);
}
Finally, call it like this最后,这样称呼
RequestServer requestServer = API .getClient().create(RequestServer.class);
requestServer.getResponse(20).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
// do something with the data here
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
// check the error and inform the user about it
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.