title: Android/Retrofit: application not communicating through http, only through https
body: <p>I'm trying to create an Android application that will communicate with a server through http protocol. I'm using Retrofit to send a GET request to the server, but I always receive the following error:</p>
  
  <pre><code>java.net.UnknownServiceException: CLEARTEXT communication to http://demo5373349.mockable.io/ not permitted by network security policy
  </code></pre>
  
  <p>While no such issue is present when trying to reach a server through https, I'll be writing the server side as well, and I'm supposed to use http.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>private TextView textView;
  private EditText editText;
  private Button getButton;
  private Retrofit retrofit;
  private ServerConnection connection;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      retrofit = new Retrofit.Builder()
              .baseUrl("http://demo5373349.mockable.io/")
              .addConverterFactory(GsonConverterFactory.create())
              .build();
  
      connection = retrofit.create(ServerConnection.class);
  
      textView = findViewById(R.id.textView);
      editText = findViewById(R.id.editText);
      getButton = findViewById(R.id.buttonGET);
      getButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              getHandler();
          }
      });
  
  }
  
  private void getHandler(){
      connection.sendGET().enqueue(new Callback&lt;Message&gt;() {
          @Override
          public void onResponse(Call&lt;Message&gt; call, Response&lt;Message&gt; response) {
              if(response.isSuccessful()) {
                  textView.setText(response.body().toString());
              }else {
                  textView.setText("Server Error");
              }
          }
  
          @Override
          public void onFailure(Call&lt;Message&gt; call, Throwable t) {
              textView.setText("Connection Error");
          }
      });
  }
  </code></pre>
  
  <p>And the interface:</p>
  
  <pre><code>public interface ServerConnection {
      @GET("./")
      Call&lt;Message&gt; sendGET();
  }
  </code></pre>