2011-01-20 74 views
4

我已經構建了使用WebView顯示asp頁面的應用程序,但有些頁面需要身份驗證(用戶名,密碼)登錄我希望我的應用程序使用我的應用程序中的用戶名和密碼自動登錄到此頁面在Android上的Android WebView登錄

這是我的代碼:


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

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


    HttpClient httpclient = new DefaultHttpClient(); 
    HttpPost httppost = new HttpPost("http://www.ucsi.edu.my/advantage/new/main.asp"); 

    try { 
     // Add your data 
     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
     nameValuePairs.add(new BasicNameValuePair("txtUserID", "12345)); 
     nameValuePairs.add(new BasicNameValuePair("txtPassword", "12345")); 
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

     // Execute HTTP Post Request 
     HttpResponse response = httpclient.execute(httppost); 

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


     mWebView.setWebViewClient(new WebViewClient()); 

回答

0

我是新手..這裏是解決方案..但犯規聽起來不錯,在所有

1)創建一個LOGI活動n ..這可以從您的應用中的菜單選項啓動,或者將其設爲默認活動,以便每當您的應用啓動時顯示第一個登錄屏幕第一個

2)獲取登錄憑證並對其進行身份驗證..如果通過,它們存儲在餅乾。我猜Android應用程序可以寫入餅乾

3)接下來在你的ASP.net網站檢查,如果任何cookie存在..如果是..獲取用戶名& PWD值,使他們自動登錄(這應該很簡單..因爲我們通常當用戶選擇記住我的選項在登錄表單)

所以現在當ur webview啓動..用戶自動登錄