sending json via put

i need to send the json string {'post_id': 3} to my server. Im using a put method. when i run it i get a 500 error from my server. am i sending the json data correctly? and help please?

   HttpClient httpclient = new DefaultHttpClient();
   HttpPut httput = new HttpPut("my url");
   HttpParams params2 = httpclient.getParams();
   HttpConnectionParams.setConnectionTimeout(params2, 30000);
   String responseBody = "";
   HttpResponse response = null;
   try {
       String base64EncodedCredentials = "Basic " + Base64.encodeToString(
           ("username"+ ":" + "password").getBytes(),
           Base64.NO_WRAP);
       httput.setHeader("Authorization", base64EncodedCredentials);
       httput.setHeader(HTTP.CONTENT_TYPE, "application/json");
       JSONObject obja = new JSONObject();
       try {

            obja.put("post_id","3");

            httput.setEntity(new StringEntity(obj.toString(), "UTF-8"));
                   // Execute HTTP Post Request
                   response = httpclient.execute(httput);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 

       ///

       HttpEntity entity= response.getEntity();
       Log.d("  ", " LIKE RESPONSE " + response.getStatusLine().getStatusCode());

Answers


you can try using Ion for make http request is more easy https://github.com/koush/ion , support headers and body params .also check the web service "500" is a Internal Server Error


Need Your Help

What is the most efficient way to determine if two line segments are part of the same segment, within a tolerance?

ruby math opencv computer-vision cluster-analysis

Edit: Changed the title. I'm less interested in the two segments being the same, but rather, if they are colinear with each other, within a certain tolerance. If so, then the lines should be cluste...

folder vs repository in github

github

I am a new user to github.com and I am trying to create a mobile app that has two parts: client code and server code. The client code will be written in Java for Android, Swift for iOS and C# for W...