1. DroidForums.net is currently undergoing a major software upgrade. If you are experiencing any problems logging in please: Contact Us

Webview with authorized Pleaes Help

Discussion in 'Android App Developers' started by askndaer, Jan 22, 2011.

  1. askndaer
    Offline

    askndaer New Member

    Joined:
    Jan 22, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi

    I have built app that display asp pages using WebView but some of the page want the authentication (Username ,Password ) to login I want whan i press login button it will display the page after login in Webview page

    Please Help

    this is the asp page
    Welcome to UCSI eAdvantage
    This is my Code:::


    package cc.tav;

    import java.io.IOException;
    import java.io.UnsupportedEncodingException;
    import java.net.URI;
    import java.net.URISyntaxException;
    import java.util.ArrayList;
    import java.util.List;

    import org.apache.http.HttpEntity;
    import org.apache.http.HttpHost;
    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity ;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
    import org.apache.http.util.EntityUtils;
    import org.apache.http.HttpHost;
    import android.app.Activity;
    import android.os.Bundle;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.TextView;

    public class cc extends Activity {
    /** Called when the activity is first created. */
    WebView mWebView;
    TextView tt;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    String returnValue = "";

    try {
    HttpHost hh = new HttpHost("www.ucsi.edu.my");

    HttpClient httpclient = new DefaultHttpClient();

    HttpPost post = new HttpPost(new URI(
    "http://www.ucsi.edu.my/advantage/new/check_user.asp"));

    post.setHeader("Content-Type", "application/x-www-form-urlencoded");

    // Add data we're going to POST & assign data to the HttpPost
    // object.
    List<NameValuePair> nvPairs = new ArrayList<NameValuePair>(2);
    nvPairs.add(new BasicNameValuePair("txtUserID", "123456"));
    nvPairs.add(new BasicNameValuePair("txtPassword", "123456"));
    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nvPairs,
    "UTF-8");
    post.setEntity(formEntity);

    // Execute POST
    HttpResponse response = httpclient.execute(post);

    // Generate String from response.
    HttpEntity entity = response.getEntity();
    returnValue = EntityUtils.toString(entity);


    System.out.println(returnValue);

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    // mWebView.loadUrl("http://www.ucsi.edu.my/ses/");

    mWebView.loadData(returnValue, "text/html/xhtml/xml",
    "gzip/deflate");

    mWebView.setWebViewClient(new WebViewClient());

    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();

    } catch (ClientProtocolException e) {
    e.printStackTrace();

    } catch (IOException e) {
    e.printStackTrace();

    } catch (URISyntaxException e) {
    e.printStackTrace();

    }

    System.out.println(returnValue);
    }

    public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
    }
    }
Search tags for this page
android webview username password
,

android webview windows authentication

,
set header for webview of android