From ee17c22f41cff696218c878a0c426d1e7dd85497 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 17 Jun 2012 07:08:33 +0200 Subject: Fix #1751: set language to English Using a simpler page and putting a referer seems to make the process more reliable. --- main/src/cgeo/geocaching/connector/gc/Login.java | 12 ++++++++---- main/src/cgeo/geocaching/network/Network.java | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'main/src') diff --git a/main/src/cgeo/geocaching/connector/gc/Login.java b/main/src/cgeo/geocaching/connector/gc/Login.java index 5584ffe..39f81f0 100644 --- a/main/src/cgeo/geocaching/connector/gc/Login.java +++ b/main/src/cgeo/geocaching/connector/gc/Login.java @@ -30,7 +30,7 @@ import java.util.regex.Matcher; public abstract class Login { - private final static String ENGLISH = "English▼"; + private final static String ENGLISH = "English▼"; // false = not logged in private static boolean actualLoginStatus = false; @@ -39,6 +39,8 @@ public abstract class Login { private static String actualStatus = ""; private final static Map gcCustomDateFormats; + public static final String LANGUAGE_CHANGE_URI = "http://www.geocaching.com/my/souvenirs.aspx"; + static { final String[] formats = new String[] { "MM/dd/yyyy", @@ -218,7 +220,7 @@ public abstract class Login { // get find count getLoginStatus(Network.getResponseData(Network.getRequest("http://www.geocaching.com/email/"))); } else { - final String page = Network.getResponseData(Network.getRequest("http://www.geocaching.com/default.aspx")); + final String page = Network.getResponseData(Network.getRequest(LANGUAGE_CHANGE_URI)); getLoginStatus(page); if (page == null) { Log.e("Failed to read viewstates to set geocaching.com language"); @@ -227,8 +229,10 @@ public abstract class Login { "__EVENTTARGET", "ctl00$uxLocaleList$uxLocaleList$ctl00$uxLocaleItem", // switch to english "__EVENTARGUMENT", ""); Login.transferViewstates(page, params); - final HttpResponse response = Network.postRequest("http://www.geocaching.com/default.aspx", params); - if (!Network.isSuccess(response)) { + final HttpResponse response = Network.postRequest(LANGUAGE_CHANGE_URI, params, new Parameters("Referer", LANGUAGE_CHANGE_URI)); + if (Network.isSuccess(response)) { + Log.i("changed language on geocaching.com to English"); + } else { Log.e("Failed to set geocaching.com language to English"); } } diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java index c73dd30..5911146 100644 --- a/main/src/cgeo/geocaching/network/Network.java +++ b/main/src/cgeo/geocaching/network/Network.java @@ -136,6 +136,18 @@ public abstract class Network { } /** + * POST HTTP request + * + * @param uri the URI to request + * @param params the parameters to add to the POST request + * @params headers the headers to add to the request + * @return the HTTP response, or null in case of an encoding error params + */ + public static HttpResponse postRequest(final String uri, final Parameters params, final Parameters headers) { + return request("POST", uri, params, headers, null); + } + + /** * Multipart POST HTTP request * * @param uri the URI to request @@ -173,9 +185,9 @@ public abstract class Network { * @param uri * the URI to request * @param params - * the parameters to add the the GET request + * the parameters to add to the URI * @param headers - * the headers to add to the GET request + * the headers to add to the request * @param cacheFile * the cache file used to cache this query * @return the HTTP response, or null in case of an encoding error in a POST request arguments -- cgit v1.1