我正在编写一个 Android 应用程序,它登录到我公司的服务器 (SSL) 并通过模拟浏览器登录来获取我的工作计划。以下代码在 Android 2.2 和 Java 中运行良好,但在 Android 4 中导致登录失败。它不会导致应用程序崩溃,但无法登录。不仅登录失败,而且将用户关闭服务器的。除非您有树连续失败的登录尝试,否则这通常不会发生。
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 {}
我已经为此苦苦挣扎了几个星期,现在我向您寻求帮助。
- Android 4 中可能有什么不同导致这不起作用(该过程未在 UI 线程中执行)。我是否可以在 apache 库中使用 HttpClient 时遇到同样的问题,或者它可能是 Jsoup 问题。
- And more importantly How can I make this work. Any hints appreciated.
The IT-department is saying the server only support login through the IE8 browser, but I have never experienced my code not to work in Android 2.2 or Java
I anyone can help me solve this I will be very thankful!