API Authenticatoin always false

Reference Application 2.11.0

Hello I am trying to authenticate through api call. I follow the guide and I make this call:

OkHttpClient client = new OkHttpClient().newBuilder().build();

        Request request = new Request.Builder()
            .url("http://62.75.188.82:8081/openmrs/ws/rest/v1/session")
            .method("GET", null)
            .addHeader("Authorization", "Basic YWRtaW46QWRtaW4xMjM=")
            .build();
    try {
        Response response = client.newCall(request).execute();
    } catch (IOException e) {
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }

java.net.UnknownServiceException: CLEARTEXT communication to 62.75.188.82 not permitted by network security policy

Can someone help me please ?

Hi @christoforos,

This error basically says that if you want to use the "Authorization" header, then you need to do it over SSL.


Then, for everyone’s record, things will happen here:

basicAuth = basicAuth.substring(6); // remove the leading "Basic "
String decoded = new String(Base64.decodeBase64(basicAuth), Charset.forName("UTF-8"));
String[] userAndPass = decoded.split(":");
Context.authenticate(userAndPass[0], userAndPass[1]);