Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Login into webview without using http requests

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 167
    Comment on it

    We know that if we want to login into some form we have to create a asyncTask to do that and then in background some lines of https requests codes and then we check for response.

    But by using webivew we can directly log in into our website without using some http requests.

    we have to specifiy urls and request parmeters that we used in our website.

    WebView myWeb;
    int mCount = 0;
    String mUrl = "www.myBlog.com";
    String mUserName;
    String mPassword;
    

    setting webview properties to enable javascript in webview

    myWeb = (WebView) findViewById(R.id.webview);
    myWeb.getSettings().setJavaScriptEnabled(true);
    
    myWeb.setWebViewClient(new WebViewClient() {
    public void onPageFinished(WebView view, String url) {
        if (mCount == 0) {
            myWeb.loadUrl(
                "javascript:document.getElementById('usernameId').value = '" + mUserName + "';"+
                "javascript:document.getElementById('passwordId').value = '" + mPassword + "';"+
                "javascript:document.getElementById('btnId').click();"
            );
            mCount++;
        } else if (mCount == 1) {
            myWeb.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
            mCount++;
        }
    }});
    

    and then load url

    myWeb.loadUrl(URL);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: