1

with the code that i will show you i get enter image description here

while i want load webview page behind login basic auth...

Ps:the auth token is correct so i think that the issue is about url that i pass to webview...but i am not able to fix the issue!

This is my 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);
    }
}
Bella
  • 145
  • 1
  • 1
  • 8

0 Answers0