0

I got a situation to test the REST API's Delete call through Java code. I need to pass Form Data with 2 variables as below screenshot to the api request. someone please route me how to do that..

enter image description here

try {                       
                URL url = new URL("http://localhost:8999/testsource");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("DELETE");
                conn.setRequestProperty("Accept", "*/*");
                conn.setRequestProperty("session", "Cii2vEBZDplu5fI9JNXiM5");

                if (conn.getResponseCode() != 200) {
                    throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
                }

                BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

                String output;
                System.out.println("Output from Server .... \n");
                while ((output = br.readLine()) != null) {
                    System.out.println(output);
                }
                conn.disconnect();
                                
        } catch (Exception e) {

                e.printStackTrace();

            }

1 Answer 1

0

Your question isn't very clear but I'll make an attempt to answer it based on the assumption that your form data contains two fields which are:

  • id

  • permanentDelete

     String data = "id=the-id-goes-here&permanentDelete=yes-or-no-goes-here";
     byte[] bytesToSend = data.getBytes(StandardCharsets.UTF_8);
     OutputStream outputStream = conn.getOutputStream();
     outputStream.write(bytesToSend);
    
Sign up to request clarification or add additional context in comments.

1 Comment

Hello @saaoc using the above code I have passed the request params but the values are not reading at REST end point level, I am getting only null values. I am using Restlet application as the REST service.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.