1

After a couple of days of fruitless searching and trying various suggestions and examples im still struggling with this.

The situation is we are developing an Android app against a DEVELOPMENT system (ie not open to use outside IT). It has a self signed certificate. The live system will have a "proper" certificate so I dont really want to be disabling the certificate check just to develop it.

The error I am receiving is a 401 Authorization error. I have tried the request with the Authorization credentials through fiddler and the REST service is chugging away nicely.

The certificate is in the Trusted credentials store on the device under user.

Here is the code that makes the connection.

try {
         StringBuilder pathName = new StringBuilder();
         StringBuilder data = new StringBuilder();

         pathName.append(getApiCall()+ path);

         URL url = new URL(pathName.toString());

         HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(Proxy.NO_PROXY);

         urlConnection.setRequestProperty("Autorization", getCredentials());
         urlConnection.setDoInput(true);
         urlConnection.setRequestMethod("GET");
         urlConnection.setRequestProperty("Content-Type", "application/json");

         try
         {
             InputStream in = urlConnection.getInputStream();
             BufferedReader r = new BufferedReader(new InputStreamReader(in));

             while ( r.readLine() != null)
             {
                 String dataLine = r.readLine();
                 data.append(dataLine);
             }
         }
         catch (Exception ex2)
         {
             int freda = urlConnection.getResponseCode();
             String fred = urlConnection.getResponseMessage();

             data.append("ERROR");
         }
         finally
         {
             urlConnection.disconnect();
         }

         return data.toString();

    }
    catch (Exception e)
    {
        return "ERROR";
    } 

If anyone could point me in the right direction I would be extremely grateful.

Thanks

Steve

MagicWand
  • 392
  • 1
  • 6
  • 19
  • If you have not solved your issue, pls take a look at [here](http://stackoverflow.com/questions/32484022/read-in-pkcs12-p12-client-cert-file-for-android-app) and [here](http://stackoverflow.com/questions/32403479/volley-ssl-hostname-was-not-verified) – BNK Sep 12 '15 at 03:12
  • Ho BNK - Thanks for that. Unfortunately the problem appears to be specific with Self Signed certificates. We have worked round it for now by going back to the "old" way to do it. Information I have found since posting suggests its some kind of bug in the android libraries. – MagicWand Sep 14 '15 at 07:52
  • I know it's been 2 years, but I have to ask... did you notice the typo with Autorization? Did it make anything work after correcting? I'm going through the same thing – Stephen J Mar 07 '18 at 20:31

0 Answers0