How to receive proper response on posting json form data to PHP server from java eclipse?

I am posting json data to the server but on getting response it should be like this

{"id":65,"check":1,"date":"08-Jan-19"}

instead i am getting this

{"id":"65check=1","check":null,"date":"08-Jan-19"}

What I have tried:

This is the code on button click i send json form data to server but in response the id value gets attached to check value, how to get proper response.

Attendance_TimeCheck = "1";
            users_identify = "65";
            try {
               URL urlForPostRequest = new URL("http://xenzet.com/ds/getrec.php");

                System.out.println("Instantiated new URL: " + urlForPostRequest);
                final long id = Long.valueOf(users_identify);
                HttpURLConnection conection = (HttpURLConnection) urlForPostRequest.openConnection();
                conection.setDoOutput(true);
                conection.setRequestMethod("POST");
                conection.setRequestProperty("User-Agent", "Mozilla/5.0");
                conection.getOutputStream().write(("id="+id).getBytes(StandardCharsets.UTF_8));
                conection.getOutputStream().write(("check="+Attendance_TimeCheck).getBytes(StandardCharsets.UTF_8));
                conection.connect();

                BufferedInputStream bis = new BufferedInputStream(conection.getInputStream());
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                int resultBuffer = bis.read();
                while (resultBuffer != -1) {
                    bos.write((byte) resultBuffer);
                    resultBuffer = bis.read();
                }
                String result1 = bos.toString();
                System.out.println(result1);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

it will be really helpful if you explain how can i post multiple values in stream is really being done.

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注