Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Jsonrpc help needed
Message
Information générale
Forum:
Android
Catégorie:
Autre
Divers
Thread ID:
01629311
Message ID:
01629389
Vues:
33
Hi Viv, I've managed to get a basic working program together by plagiarising some code from one of the links you posted - it ain't pretty yet and I'm sure there's a better way of doing it but it works, I build the request string manually and call the method below which gives me raw json in return - this will do for now but as always I'm open to suggestions - thanks for your help
 private JSONObject doJSONRequest(JSONObject jsonRequest,String Server)
    {
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost request = new HttpPost(Server);
        JSONObject jsonResponse = null;

        HttpResponse response = null;
        String responseString = null;
        JSONEntity entity = null;

        try
        {
            entity = new JSONEntity(jsonRequest);
        }
        catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        }


        request.setEntity(entity);


        try
        {
            response = httpClient.execute(request);
            responseString = EntityUtils.toString(response.getEntity()).trim();
            jsonResponse = new JSONObject(responseString);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        return jsonResponse;
    }
Helper class
class JSONEntity extends StringEntity
    {
        public JSONEntity(JSONObject jsonObject) throws UnsupportedEncodingException
        {
            super(jsonObject.toString());
        }

        public Header getContentType()
        {
            return new BasicHeader("Content-Type", "application/json");
        }
    }
Regards,
Peter J. Kane



Pete
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform