I am writing an Android app which logs into my company’s server (SSL) and gets my work schedule by simulating a browser login. The following code is working perfectly in Android 2.2 and Java, but causes a failed login in Android 4. It does not cause the app to crash, but can not log in. Not only is it faling in logging in, it shuts the user out of the server. This normally does not happen unless you hav tree consecutive failed login attempts.
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 {}
I have been struggeling with this for several weeks now am now turning to you for help.
- What may be diffent in Android 4 causing this not to work (The process is not beeng performed in the UI thread). Can I expext to have the same problem using HttpClient off the apache library, or can it be a Jsoup problem.
- 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!
I solved it by using the apache library iso Jsoup. Then I use Jsoup to parse the resposeBody from HttpClient. Works great.