I am posting json data to the server but on getting response it should be like this
Hide Copy Code
{"id":65,"check":1,"date":"08-Jan-19"}
instead i am getting this
Hide Copy Code
{"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.
Hide Expand Copy Code
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.
发表回复