0

I used to post json stringer using the following code but having lot of deprecation warning.Can anyone help me out to show me the correct way for POSTing.Please have a look on my code that i'm using for posting currently.

HttpPost httppost = new HttpPost(F_URL);

                    System.out.println("URL...." + F_URL);

                    httppost.setHeader("Accept", "application/json");
                    httppost.setHeader("Content-Type", "application/json");
                    JSONStringer jsonStringer = new JSONStringer().object()
                            .key("putmicdata").object().key("CompanyID")
                            .value(companyid).key("ValueHeader")
                            .value(valueheader).key("ValueHeaderDetail")
                            .value(valueheaderdetail).endObject();
                    StringEntity entity = new StringEntity(
                            jsonStringer.toString());

                    System.out.println("String...."
                            + jsonStringer.toString());
                    entity.setContentType(new BasicHeader(
                            HTTP.CONTENT_TYPE, "application/json"));
                    httppost.setEntity(entity);

                    response = httpclient.execute(httppost);

                    StatusLine statusLine = response.getStatusLine();
                    int statusCode = statusLine.getStatusCode();

                    System.out.println("StatusCode for MIC" + statusCode);

                    if (response != null) {
                        HttpEntity httpEntity = response.getEntity();
                        total = EntityUtils.toString(httpEntity);
                        dbhelper.getWritableDatabase();
                        dbhelper.DELETE_MICUOMINTERNAL(loc);
                        dbhelper.closeDatabase();
                    }

                    result = "success";
Vikash Kumar
  • 395
  • 5
  • 17

1 Answers1

1

you can use HttpUrlConnectionor if you want just opening a webaddress just use

new URL("youraddress.com").openStream();
karimkhan
  • 321
  • 3
  • 18
  • Can you please provide me some references for posting json to server using HttpUrlConnection....that will be very helpful as i'm new to this. – Vikash Kumar Jan 05 '16 at 19:30
  • @VikashKumar: sure [ref1](http://developer.android.com/intl/es/reference/java/net/HttpURLConnection.html)and [ref2](http://stackoverflow.com/questions/13911993/sending-a-json-http-post-request-from-android) – karimkhan Jan 05 '16 at 19:35