2012-09-13 61 views
0

我正在編寫一個Android應用程序,它登錄到我公司的服務器(SSL)並通過模擬瀏覽器登錄來獲得我的工作時間表。以下代碼在Android 2.2和Java中完美運行,但會導致Android 4登錄失敗。它不會導致應用程序崩潰,但無法登錄。它不僅在登錄時觸發,還會關閉用戶的服務器。這通常不會發生,除非您連續失敗的登錄嘗試。Jsoup和ICS登錄失敗

static final Sting host0 = "http://someplace.com" 
static final Sting host1 = "https://someplace.com/login"; 
static final String userAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)" 
System.setProperty("http.keepAlive", "true"); 

try{ 
Connection.Response res = Jsoup.connect(host0) 
     .userAgent(userAgent) 
     .followRedirects(true) 
     .method(Method.GET) 
     .execute(); 
cookies1 = res.cookies(); 

Connection.Response res1 = Jsoup.connect(host) 
     .data("label1","calue1", 
       "label2","calue2", 
       "label3","calue3", 
       "label4","calue4") 
       .cookies(cookies1) 
       .userAgent(userAgent) 
       .followRedirects(true) 
       .method(Method.POST) 
       .execute(); 

Connection.Response res2 = Jsoup.connect(host) 
     .data("label5","calue15", 
       "label6","calue6", 
       "label7","calue7", 
       "label18","calue8") 
       .cookies(cookies1) 
       .userAgent(userAgent) 
       .followRedirects(true) 
       .method(Method.POST) 
       .timeout(10000) 
       .execute(); 
} 
catch (IOException ioe) { 
    ioe.printStackTrace(); 
    System.out.println("IOException handled in initializeDocArray()"); 
} 
finally {} 

我一直在爲此奮鬥了好幾個星期,現在我正轉向你尋求幫助。

  1. Android 4中有什麼不同可能導致這種情況不起作用(該過程不在UI線程中執行)。我是否可以使用HttpClient從apache庫中獲取相同的問題,或者它可能是一個Jsoup問題。
  2. 更重要的是,我該如何做這項工作。任何提示讚賞。

的IT-部門稱該服務器只能通過IE8瀏覽器支持登錄,但我從來沒有經歷過我的代碼不能在Android 2.2或Java的工作

我任何人都可以幫我解決這個我會非常感謝!

回答

0

我解決了它通過使用apache庫iso jsoup。然後我使用Jsoup來解析HttpClient的resposeBody。很棒。