0

I want to request a webservice with https url, but a Volley Error Occurs (NoConnectionError). I think the problem is that https url, but I don't found any solution on internet. Anybody can helps me?

The error is: "com.android.volley.NoConnectionError: java.io.IOException: No authentication challenges found"

Code:

    RequestQueue queue = VolleySingleton.getInstance(this).getRequestQueue();

    String url = "https://www.websiteco.com/rest/index.php/login/user/email/ana@gmail.com/password/123456";

    JsonObjectRequest json = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            String s = response.toString();
        }

    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

            String errorStr = "";

            if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                errorStr = "TimeoutError or NoConnectionError";
            } else if (error instanceof AuthFailureError) {
                errorStr = "AuthFailureError";
            } else if (error instanceof ServerError) {
                errorStr = "ServerError";
            } else if (error instanceof NetworkError) {
                errorStr = "NetworkError";
            } else if (error instanceof ParseError) {
                errorStr = "ParseError";
            }

            Toast.makeText(getApplicationContext(),errorStr,Toast.LENGTH_LONG).show();

        }
    }) {

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> parms = new HashMap<>();
            parms.put("Key-Api", "*******");
            return parms;
        }

        @Override
        protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
            try {
                String jsonString = new String(response.data,
                        HttpHeaderParser.parseCharset(response.headers));
                return Response.success(new JSONObject(jsonString),
                        HttpHeaderParser.parseCacheHeaders(response));
            } catch (UnsupportedEncodingException e) {
                return Response.error(new ParseError(e));
            } catch (JSONException je) {
                return Response.error(new ParseError(je));
            }
        }
    };

    queue.add(json);

Vinicius Maciel
  • 101
  • 2
  • 12
  • Is your method working with `http` ?? – SripadRaj Jun 28 '16 at 17:37
  • 1
    Yes, this method working with http. But I should use https in this case. – Vinicius Maciel Jun 28 '16 at 17:39
  • @SripadRaj Did you see this error before "com.android.volley.NoConnectionError: java.io.IOException: No authentication challenges found"? – Vinicius Maciel Jun 28 '16 at 17:40
  • As per my experience, there will be an `SSLHandshakeException` if the `https` url is not signed. This will sometime throw a Network error. So I suggest you to get the signed `https` url or the android device will not be able to make any network calls to that url. – SripadRaj Jun 28 '16 at 17:43
  • I understand you. Did you know, how I can do a Self-signed with Volley? A long time I'm searching on web and nothing – Vinicius Maciel Jun 28 '16 at 17:51
  • You have to use a `TrustManager`. [This SO post](http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https) might help you. :) – SripadRaj Jun 28 '16 at 17:57
  • @SripadRaj I make this TrustManager but still the error http://pt.androids.help/q3366 – Vinicius Maciel Jun 28 '16 at 18:25

0 Answers0