【发布时间】:2018-01-30 18:49:22
【问题描述】:
我有一个链接和一个 API:
@GET("users/{username}")
Call<String> getStringResponse(@Path("username") String username);
public class APIClientDetail {
public Retrofit getRetrofit(String baseUrl) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(ScalarsConverterFactory.create())
// add other factories here, if needed.
.build();
return retrofit;
}
}
我打电话:
APIClientDetail apiClientDetail= new APIClientDetail();
Retrofit retrofit= apiClientDetail.getRetrofit("https://www.youtube.com/watch?v=");
GitHubService scalarService = retrofit.create(GitHubService.class);
Call<String> stringCall = scalarService.getStringResponse("EMyW7WvhEso");
stringCall.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
if (response.isSuccessful()) {
String responseString = response.body();
// todo: do something with the response string
modelInterface.dataSuccessful();
}
}
@Override
public void onFailure(Call<String> call, Throwable t) {
modelInterface.dataError();
}
});
但是不行,进不了函数onResponse。
【问题讨论】:
-
它会转到
onFailure吗?!您可以在 onFailure 中打印t.getMessage()并将其添加到您的问题中,以了解更多关于发生了什么的线索吗? -
在检查 if 条件之前,只需放一个日志,看看你得到什么响应
-
当我使用链接时:gateway.fpts.com.vn/g5g/fpts/?s=realtime_index_ho ---------------- baseUrl: gateway.fpts .com.vn/g5g/fpts ---------- @GET("") Call
getStringResponse(@Query("s") String姓名);它不起作用!