D
D
Denis Loboda2018-04-04 16:13:40
Android
Denis Loboda, 2018-04-04 16:13:40

How to write a GET request for Unsplash?

When executing the request, an error occurs:

error: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x51859170: Failure in SSL library, usually a protocol error
    error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version (external/openssl/ssl/s23_clnt.c:741 0x4e9ab898:0x00000000)

The code:
public interface PhotoLink
{
 
    @GET("/photos")
    Observable<JsonObject> getPhotoList(@Query("client_id") String client_id);
}
 
public class ListPhotoPresenter extends MvpBasePresenter<ListPhotoView> implements IListPhotoPresenter
{
    private final String URL = "https://api.unsplash.com";
    private final String KEY = "5a56756e4fd4b387aa6c1adf99efb0c17bcbbaa2a99ed0b21ba";
 
    Gson gson = new GsonBuilder().create();
    Retrofit retrofit = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl(URL)
            .build();
 
    PhotoLink inf = retrofit.create(PhotoLink.class);
 
    @Override
    public void init()
    {
        Map<String, String> map = new HashMap<>();
        map.put("client_id", KEY);
 
        Observable<JsonObject> call = inf.getPhotoList(KEY); //здесь возникает ошибка 
        call
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<JsonObject>()
                {
                    @Override
                    public void onSubscribe(Disposable d)
                    {
 
                    }
 
                    @Override
                    public void onNext(JsonObject value)
                    {
                        String str = value.toString();
                        PhotoList w = gson.fromJson(str, PhotoList.class);
                    }
 
                    @Override
                    public void onError(Throwable e)
                    {
                        Log.d("myLog","error: " + e.getMessage());
                    }
 
                    @Override
                    public void onComplete()
                    {
 
                    }
                });
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Loboda, 2018-04-05
@Darkos-den

Problem solved, it was necessary to use a different version of TLS. I took the solution from this article.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question