aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-06-17 07:08:33 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-06-17 07:11:22 +0200
commitee17c22f41cff696218c878a0c426d1e7dd85497 (patch)
tree01d565e21731b876ef858560b6d51ee60c5f1702 /main/src
parent16f8ce395dbadbb4f1ff15b529d3a4280d45777e (diff)
downloadcgeo-ee17c22f41cff696218c878a0c426d1e7dd85497.zip
cgeo-ee17c22f41cff696218c878a0c426d1e7dd85497.tar.gz
cgeo-ee17c22f41cff696218c878a0c426d1e7dd85497.tar.bz2
Fix #1751: set language to English
Using a simpler page and putting a referer seems to make the process more reliable.
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/connector/gc/Login.java12
-rw-r--r--main/src/cgeo/geocaching/network/Network.java16
2 files changed, 22 insertions, 6 deletions
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&#9660;";
+ private final static String ENGLISH = "<a href=\"#\">English&#9660;</a>";
// 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<String, SimpleDateFormat> 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