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);
}
}