From 22eb846a28184c341826082c219d57defaccd6c0 Mon Sep 17 00:00:00 2001 From: Zhehua Chang Date: Tue, 1 Mar 2016 20:56:41 +0800 Subject: [PATCH] Fix symbol password failure via OkHTTP. Fix close warning by OkHTTP. --- app/app.iml | 40 ++++++++++++------- .../zchang/onchart/session/BitJwcSession.java | 17 +++++--- .../me/zchang/onchart/session/Session.java | 3 +- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/app/app.iml b/app/app.iml index 0735baa..50acdf6 100644 --- a/app/app.iml +++ b/app/app.iml @@ -65,46 +65,56 @@ + - + + + + + + + + + + + - - - - - - - - - - - + - + - - + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/me/zchang/onchart/session/BitJwcSession.java b/app/src/main/java/me/zchang/onchart/session/BitJwcSession.java index 11f16b9..73c766a 100644 --- a/app/src/main/java/me/zchang/onchart/session/BitJwcSession.java +++ b/app/src/main/java/me/zchang/onchart/session/BitJwcSession.java @@ -12,6 +12,7 @@ import org.greenrobot.eventbus.EventBus; import java.io.IOException; +import java.net.SocketTimeoutException; import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -78,7 +79,7 @@ public void run() { RequestBody formBody = new FormEncodingBuilder() .add("__VIEWSTATE", "dDwtMjEzNzcwMzMxNTs7Pj9pP88cTsuxYpAH69XV04GPpkse") .add("TextBox1", stuNum) - .add("TextBox2", pswToUnicode(psw)) + .add("TextBox2", psw) .add("RadioButtonList1", "%D1%A7%C9%FA") .add("Button1", "+%B5%C7+%C2%BC+") .build(); @@ -91,6 +92,7 @@ public void run() { homeRequest = homeRequest.newBuilder().addHeader("Referer", loginUrl).build(); Response homePage = httpClient.newCall(homeRequest).execute(); startResponse = homePage.body().string(); + homePage.body().close(); stuName = fetchName(); if (stuName != null) {// name detected, as good as account validation. isStarted = true; @@ -130,6 +132,7 @@ public void run() { EventBus.getDefault().post( new ScheduleFetchOverEvent(StudentInfoParser.parseCourses(scheduleResponse.body().string()), "default") ); + scheduleResponse.body().close(); Log.i(MainActivity.TAG, "post schedule fetch over"); } } catch (IOException e) { @@ -177,6 +180,7 @@ public void call(Subscriber> subscriber) { subscriber.onNext( StudentInfoParser.parseParamsInCoursePage(scheduleResponse.body().string()) ); + scheduleResponse.body().close(); } } catch (IOException e) { e.printStackTrace(); @@ -211,6 +215,7 @@ public void call(Subscriber subscriber) { Log.i(TAG, "fetch schedule request sent"); Response response = httpClient.newCall(scheduleRequest).execute(); subscriber.onNext(response.body().string()); + response.body().close(); subscriber.onCompleted(); } catch (IOException e) { e.printStackTrace(); @@ -264,6 +269,7 @@ public void run() { weekResponse = httpClient.newCall(request).execute(); if (weekResponse.isSuccessful()) { EventBus.getDefault().post(new HomepageFetchOverEvent(StudentInfoParser.parseWeek(weekResponse.body().string()))); + weekResponse.body().close(); } } catch (IOException e) { EventBus.getDefault().post(new SessionErrorEvent(ErrorCode.SESSION_EC_FETCH_WEEK)); @@ -298,6 +304,7 @@ public List fetchExams() throws IOException { Response examResponse = httpClient.newCall(request).execute(); if (examResponse.isSuccessful()) { String htmlRes = examResponse.body().string(); + examResponse.body().close(); return StudentInfoParser.parseExams(htmlRes); } return new ArrayList<>(); @@ -309,20 +316,20 @@ public List fetchExams() throws IOException { * @return coverted password */ public String pswToUnicode(String psw) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int length = psw.length(); char c; int temp; for (int i = 0;i < length;i ++) { c = psw.charAt(i); - if((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c <= 'a' && c >= 'z')) { + if((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c <= 'a' && c >= 'z') + || c == '*' || c == '_' || c == '-' || c == '.') { sb.append(c); } else { temp = c; - sb.append("%" + String.format("%x", temp)); + sb.append("%").append(String.format("%x", temp).toUpperCase()); } } - return sb.toString(); } diff --git a/app/src/main/java/me/zchang/onchart/session/Session.java b/app/src/main/java/me/zchang/onchart/session/Session.java index 6b2782a..384a14a 100644 --- a/app/src/main/java/me/zchang/onchart/session/Session.java +++ b/app/src/main/java/me/zchang/onchart/session/Session.java @@ -56,7 +56,8 @@ public enum ErrorCode { SESSION_EC_INVALID_ACCOUNT, SESSION_EC_FETCH_SCHEDULE, SESSION_EC_FETCH_EXAM, - SESSION_EC_FETCH_WEEK + SESSION_EC_FETCH_WEEK, + SESSION_EC_SOCKET_TIMEOUT } public String getStuNum() {