改造 2 搜索注释



我想调用 GitHub API 根据任意搜索参数返回存储库列表,如下所示:https://api.github.com/search/repositories?q=custom_search_param

因此,custom_search_param是在运行时声明的。

我做了这个界面:

public interface GitHubClient {
String BASE_URL = "https://api.github.com/";
@GET("search/repositories")
Call<GitHubRepo> getReposForSearchParam (@Query("q") String custom_search_param);
}

我在 MainActivity onCreate 中调用它,如下所示:

Retrofit retrofit = new Retrofit.Builder().baseUrl(GitHubClient.BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
GitHubClient gitHubClient = retrofit.create(GitHubClient.class);
Call<GitHubRepo> call = gitHubClient.getReposForSearchParam("tetris");
call.enqueue(new Callback<GitHubRepo>() {
@Override
public void onResponse(Call<GitHubRepo> call, Response<GitHubRepo> response) {
Log.d("resp",response.toString());
Log.d("respBody",response.body().toString());
}
@Override
public void onFailure(Call<GitHubRepo> call, Throwable t) {
Log.e("wentWrong", t.getMessage());
}
});

我总是得到onFailure这条消息的回应:

E/wentWrong: javax.net.ssl.SSLProtocolException: SSL handshake 已中止:ssl=0xb8679dd0:SSL 库中失败,通常是协议 错误 错误:1407742E:SSL 例程:SSL23_GET_SERVER_HELLO:tlsv1 警报 协议版本(外部/OpenSSL/SSL/s23_clnt.C:741 0x9db10901:0x000

00000(

有谁知道这里出了什么问题,以及 GitHubClient 接口分配是否应该以不同的方式声明?

由于GitHub api已禁用TLSv1.1,因此您至少需要一个支持TLSv1.1的设备或客户端。因此,对于低于android 4.4的Android设备,它将不起作用。看这里。

最新更新