Click here to Skip to main content
16,004,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


Java
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.
Posted
Comments
Richard MacCutchan 16-Jan-19 9:47am    
You need to talk to the owners of the website that is returning the bad data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900