aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/network/Network.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/network/Network.java')
-rw-r--r--main/src/cgeo/geocaching/network/Network.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java
index 2545f4d..a4155be 100644
--- a/main/src/cgeo/geocaching/network/Network.java
+++ b/main/src/cgeo/geocaching/network/Network.java
@@ -383,13 +383,21 @@ public abstract class Network {
return response != null && response.getStatusLine().getStatusCode() == 200;
}
+ /**
+ * Get the result of a GET HTTP request returning a JSON body.
+ *
+ * @param uri the base URI of the GET HTTP request
+ * @param params the query parameters, or <code>null</code> if there are none
+ * @return a JSON object if the request was successful and the body could be decoded, <code>null</code> otherwise
+ */
public static JSONObject requestJSON(final String uri, final Parameters params) {
final HttpResponse response = request("GET", uri, params, new Parameters("Accept", "application/json, text/javascript, */*; q=0.01"), null);
- if (isSuccess(response)) {
+ final String responseData = Network.getResponseData(response, false);
+ if (responseData != null) {
try {
- return new JSONObject(Network.getResponseData(response));
+ return new JSONObject(responseData);
} catch (final JSONException e) {
- Log.e("Network.requestJSON", e);
+ Log.w("Network.requestJSON", e);
}
}
@@ -406,10 +414,26 @@ public abstract class Network {
}
}
+ /**
+ * Get the body of a HTTP response.
+ *
+ * {@link BaseUtils#replaceWhitespace(String)} will be called on the result
+ *
+ * @param response a HTTP response, which can be null
+ * @return the body if the response comes from a successful HTTP request, <code>null</code> otherwise
+ */
public static String getResponseData(final HttpResponse response) {
return Network.getResponseData(response, true);
}
+ /**
+ * Get the body of a HTTP response.
+ *
+ * @param response a HTTP response, which can be null
+ * @param replaceWhitespace <code>true</code> if {@link BaseUtils#replaceWhitespace(String)}
+ * should be called on the body
+ * @return the body if the response comes from a successful HTTP request, <code>null</code> otherwise
+ */
public static String getResponseData(final HttpResponse response, boolean replaceWhitespace) {
if (!isSuccess(response)) {
return null;