title: How to load webpage in Android webview with basic authentication
body: <p>with the code that i will show you i get <a href="https://i.stack.imgur.com/lwOao.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lwOao.png" alt="enter image description here"></a></p>
  
  <p>while i want load <code>webview</code> page behind login <code>basic auth</code>...</p>
  
  <p>Ps:the <code>auth token</code> is correct so i think that the issue is about <code>url</code> that i pass to webview...but i am not able to fix the issue!</p>
  
  <p>This is my code:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          WebView webView = (WebView) findViewById(R.id.webView);
  
          setSupportActionBar(toolbar);
  
         /* FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                          .setAction("Action", null).show();
              }
          });*/
          URL url = null;
  
          try {
              url = new URL("https://unimol.esse3.cineca.it/auth/Logon.do");
          } catch (MalformedURLException e) {
  
          }
          HttpURLConnection httpRequest = null;
          try {
              httpRequest = (HttpURLConnection) url.openConnection();
          } catch (IOException e) {
  
          }
          try {
              httpRequest.setRequestMethod("GET");
          } catch (ProtocolException e) {
  
          }
          httpRequest.setDoInput(true);
          String authString = "myUser" + ":" + "myPass";
          byte[] authEncBytes = android.util.Base64.encode(authString.getBytes(), android.util.Base64.DEFAULT);
          String authStringEnc = new String(authEncBytes);
          httpRequest.addRequestProperty("Authorization", "Basic " + authStringEnc);
          System.out.println("auth:" + "" + authStringEnc);
          webView.loadUrl("https://unimol.esse3.cineca.it/auth/Logon.do");
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>