This code runs the onFailure function.
OkHttpClient client;
client = new OkHttpClient();
here the url is a http url.
Request request = new Request.Builder().url("http://www.example.com").build();
client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
                textView.setText("Failed to get response");
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if(response.isSuccessful()){
                    final String myResponse = response.body().string();
                    MainActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            textView.setText(myResponse);
                        }
                    });
                }
            }
        });
but when url is a https url like
Request request = new Request.Builder().url("https://www.example.com").build();
then onResponse is called.
How can make this work for http websites. The website I need this to work on is a http only website.
