diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2012-12-18 08:52:38 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2012-12-18 08:52:38 +0100 |
| commit | 61e692ccaaccd779129177c9b27b6ff5ae1bb891 (patch) | |
| tree | 517f67acb6757de03d651fd7b3d2e71d0b9eeee9 /main/src/cgeo/geocaching/network | |
| parent | 0136bc8dbd6e7c2a97b05bb8bcb563f9723d5077 (diff) | |
| parent | b2951e465ca783c4eab32e642ed885625b417f12 (diff) | |
| download | cgeo-61e692ccaaccd779129177c9b27b6ff5ae1bb891.zip cgeo-61e692ccaaccd779129177c9b27b6ff5ae1bb891.tar.gz cgeo-61e692ccaaccd779129177c9b27b6ff5ae1bb891.tar.bz2 | |
Merge branch 'cache_coords_wpt_ng' of https://github.com/triakcz/c-geo-opensource into upstream
Diffstat (limited to 'main/src/cgeo/geocaching/network')
| -rw-r--r-- | main/src/cgeo/geocaching/network/Network.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java index 2b81b9e..54f9eff 100644 --- a/main/src/cgeo/geocaching/network/Network.java +++ b/main/src/cgeo/geocaching/network/Network.java @@ -22,6 +22,7 @@ import ch.boye.httpclientandroidlib.client.methods.HttpGet; import ch.boye.httpclientandroidlib.client.methods.HttpPost; import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; import ch.boye.httpclientandroidlib.client.params.ClientPNames; +import ch.boye.httpclientandroidlib.entity.StringEntity; import ch.boye.httpclientandroidlib.entity.mime.MultipartEntity; import ch.boye.httpclientandroidlib.entity.mime.content.FileBody; import ch.boye.httpclientandroidlib.entity.mime.content.StringBody; @@ -156,6 +157,28 @@ public abstract class Network { } /** + * POST HTTP request with Json POST DATA + * + * @param uri the URI to request + * @param json the json object to add to the POST request + * @return the HTTP response, or null in case of an encoding error params + */ + public static HttpResponse postJsonRequest(final String uri, final JSONObject json) { + HttpPost request; + request = new HttpPost(uri); + request.addHeader("Content-Type", "application/json; charset=utf-8"); + if (json != null) { + try { + request.setEntity(new StringEntity(json.toString())); + } catch (UnsupportedEncodingException e) { + Log.e("postJsonRequest:JSON Entity: UnsupportedEncodingException"); + return null; + } + } + return doRepeatedRequests(request); + } + + /** * Multipart POST HTTP request * * @param uri the URI to request |
