问题描述
我正在使用retrofit2,但是它不起作用,当我键入检索到的Json时,它正在键入“ javax.net.ssl.SSlProtocolException:SSL握手异常中止”(虽然应用程序没有崩溃)。我正在学习一个教程,对家教来说一切都很好,但对我而言却不是。有什么帮助吗? 注意:我正在使用api级别为19的android智能手机
`Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://jsonplaceholder.typicode.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
//haide bt5line sir est3ml lmethods b2lb l JsonPlaceHolderApi interface
JsonPlaceHolderApi jsonPlaceHolderApi = retrofit.create(JsonPlaceHolderApi.class);
Call<List<Post>> call = jsonPlaceHolderApi.getPosts();
call.enqueue(new Callback<List<Post>>() {
@Override
public void onResponse(Call<List<Post>> call,Response<List<Post>> response) {
if(!response.isSuccessful())
{
text.setText(response.code() + "");
return;
}
List<Post> posts = response.body(); //ldata
for(Post post: posts)
{
String content = "";
content += "Id: " + post.getId() + "\n" ;
content += "UserId: " + post.getUserId() + "\n" ;
content += "Title: " + post.getTitle() + "\n" ;
content += "Text: " + post.getText() + "\n" ;
text.append(content);
}
}
@Override
public void onFailure(Call<List<Post>> call,Throwable t) {
text.setText(t.getMessage());
}
});`
等级:
dependencies {
implementation fileTree(dir: "libs",include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)