2011-06-22 251 views
1

首先,我對此非常陌生。我是新來的Android,asp,javascript,甚至http。通過Android應用登錄https網站

我試圖建立一個Android應用程序,允許我登錄到我的學校的網站和拉斷的數據是,最終我希望能像做插入我的時間表的數據轉換成Android的日曆項。但是我無法登錄

這裏的網站: https://sso.wis.ntu.edu.sg/webexe88/owa/sso_login2.asp

我在做什麼目前正在做一個HTTP POST到上述網址,我希望被重定向到hhttps ://wish.wis.ntu.edu.sg/pls/webexe/aus_stars_check.check_subject_web2這將顯示我的時間表。

到目前爲止,我的代碼是查看網頁的源代碼,並搜索了不少在互聯網上依次如下:

private void start_login(String[] array) { 
    // TODO Auto-generated method stub 
    Toast.makeText(this, "Logging in...", Toast.LENGTH_LONG).show(); 

    WebView wv = new WebView(this);  
    this.setContentView(wv); 

    try { 

     ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4); 
     nameValuePairs.add(new BasicNameValuePair("UserName", <my username here>)); 
     nameValuePairs.add(new BasicNameValuePair("PIN", <my password here>)); 
     nameValuePairs.add(new BasicNameValuePair("Domain", "STUDENT")); 
     nameValuePairs.add(new BasicNameValuePair("p2", "https://wish.wis.ntu.edu.sg/pls/webexe/aus_stars_check.check_subject_web2")); 

     wv.loadData(CustomHttpClient.executeHttpPost(URL, nameValuePairs), "text/html", "utf-8"); 

    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

}// end start_login 

這就是登錄功能。

我使用的CustomHttpClient是得益於這個傢伙:http://www.newtondev.com/2010/07/27/making-http-requests-using-google-android/

到目前爲止,我沒有得到任何結果。我究竟做錯了什麼?我是否缺少ArrayList中的值,或者我得到的URL全錯了?

回答

3

下面的代碼處理HTTPS並給出httpsclient爲HTTPS URL ..你需要httpsclient製作要求HTTPS URL中。

強權下面的代碼是對你有所幫助:

public DefaultHttpClient getClient() 
    { 
     DefaultHttpClient ret = null; 

     //sets up parameters 
     HttpParams params = new BasicHttpParams(); 
     HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 
     HttpProtocolParams.setContentCharset(params, "utf-8"); 
     params.setBooleanParameter("http.protocol.expect-continue", false); 

     //registers schemes for both http and https 
     SchemeRegistry registry = new SchemeRegistry(); 
     registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
     final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); 
     sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); 
     registry.register(new Scheme("https", sslSocketFactory, 443)); 

     ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); 
     ret = new DefaultHttpClient(manager, params); 
     return ret; 
    } 
+0

感謝一大堆success_anil!這對我有效! – squeeish