0

I am trying to fetch the user information about user ID 1 from a api and log it, however I keep running into the following error:

E/Rest response: com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0x7c74f2dc88: I/O error during system call, Connection reset by peer

This is my first time working with an RESTful API so I am a bit inexperienced. I have tried to find solutions to this problem on stack overflow but they do not seem to work. I have seen that some users mention that this is a commonly occurring error for Android devices below Android API 22 5.1 Lollipop, however I am using Android 6.0 Marshmallow and am still receiving this error.

This is my code:

public class MainActivity extends AppCompatActivity {

String url = "https://ecoproduce.eu/api/User/1";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

        final SSLSocketFactory sslSocketFactory;
        try {
            sslSocketFactory = new TLSSocketFactory();
            HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
        } catch (KeyManagementException ignored) {

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

    RequestQueue requestQueue = Volley.newRequestQueue(this);

    JsonObjectRequest objectRequest = new JsonObjectRequest(
            Request.Method.GET,
            url,
            null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.e("Rest response", response.toString());
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("Rest response", error.toString());
                }
            }
    );

    requestQueue.add(objectRequest);
}

}

Vasko Vasilev
  • 554
  • 1
  • 10
  • 25
  • 1
    Are you serving your endpoint over _https?_ It looks like you're using plain HTTP, and Volley expects an SSL handshake. – 9000 Feb 25 '20 at 17:20
  • I have this code from a tutorial I was following. Originally, the url was http, however I changed it to https because I received the following error: E/Rest response: com.android.volley.NoConnectionError: java.io.IOException: Cleartext HTTP traffic to ecoproduce.eu not permitted. Will change back to http and find another solution. – Vasko Vasilev Feb 25 '20 at 17:24
  • Try connecting to [https://ecoproduce.eu/api/User/1](https://ecoproduce.eu/api/User/1) right from your browser, and see that _they_ are having a problem in the SSL setup. Your code may be completely fine. – 9000 Feb 25 '20 at 17:31

1 Answers1

0

Solved by switching the url string from

String url = "https://ecoproduce.eu/api/User/1";

to

String url = "http://ecoproduce.eu/api/User/1";

and adding

android:usesCleartextTraffic="true"

in the android manifest file. Answer found on the following link: Android 8: Cleartext HTTP traffic not permitted

Vasko Vasilev
  • 554
  • 1
  • 10
  • 25