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";
1

1 Answer 1

1

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

new URL("youraddress.com").openStream();
2
  • 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. Jan 5, 2016 at 19:30
  • @VikashKumar: sure ref1and ref2
    – karimkhan
    Jan 5, 2016 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.