diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2011-10-18 19:28:44 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2011-10-18 19:28:44 +0200 |
| commit | dbea89f42ea47333a7e06fe62c64c17660e8bb32 (patch) | |
| tree | 305d9df55f9a3fdeea657230b0303649b19abc69 /main | |
| parent | afaff63b3bd2881b5e4d7dbb84380c3fade544cd (diff) | |
| download | cgeo-dbea89f42ea47333a7e06fe62c64c17660e8bb32.zip cgeo-dbea89f42ea47333a7e06fe62c64c17660e8bb32.tar.gz cgeo-dbea89f42ea47333a7e06fe62c64c17660e8bb32.tar.bz2 | |
Do not return useless result from switchToEnglish
Also, in general, do not extract the content from a failed HTTP
transaction (status code not equal to 200).
Diffstat (limited to 'main')
| -rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 63d9fff..b5c0b30 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -534,13 +534,16 @@ public class cgBase { return false; } - public static String switchToEnglish(final String[] viewstates) { + public static void switchToEnglish(final String[] viewstates) { final Parameters params = new Parameters( "__EVENTTARGET", "ctl00$uxLocaleList$uxLocaleList$ctl00$uxLocaleItem", // switch to english "__EVENTARGUMENT", ""); setViewstates(viewstates, params); - return cgBase.getResponseData(postRequest("http://www.geocaching.com/default.aspx", params)); + final HttpResponse response = postRequest("http://www.geocaching.com/default.aspx", params); + if (!isSuccess(response)) { + Log.e(Settings.tag, "Failed to set geocaching.com language to English"); + } } public static cgCacheWrap parseSearch(final cgSearchThread thread, final String url, String page, final boolean showCaptcha) { @@ -2742,7 +2745,7 @@ public class cgBase { } static public String getResponseData(final HttpResponse response) { - if (response == null) { + if (!isSuccess(response)) { return null; } try { @@ -2855,6 +2858,10 @@ public class cgBase { return String.format(" (%d ms) ", System.currentTimeMillis() - before); } + static public boolean isSuccess(final HttpResponse response) { + return response != null && response.getStatusLine().getStatusCode() == 200; + } + static public HttpResponse doRequest(final HttpRequestBase request) { final String reqLogStr = request.getMethod() + " " + hidePassword(request.getURI().toString()); Log.d(Settings.tag, reqLogStr); |
