Pub.client:http Method Delete Rest service with request body as payload Json

Hi Guys,

This is my experience to thank you, My Software AG Designer 10.3 on pub.client:http I can’t pass body on Method delete ,This is a known scenario and Integration Server doesn’t accept request body for HTTP DELETE Method.

i use Java Service like this so HTTP method DELETE can use payload json

  1. The first i imported the httpclient jar.
  2. the second i use java source code :
		String resultJson = null;
		String rescode = null;
		String jsonInputString = jsonBodyString;
		try {
			
		url = new URL (uri);
		
		HttpURLConnection con = (HttpURLConnection)url.openConnection();
		con.setRequestMethod("DELETE");
		
		con.setRequestProperty("Content-Type", "application/json; utf-8");
		con.setRequestProperty("Accept", "application/json");
		
		con.setDoOutput(true);
		try(OutputStream os = con.getOutputStream()){
			byte[] input = jsonInputString.getBytes("utf-8");
			os.write(input, 0, input.length);			
		}
		
		int code = con.getResponseCode();
		rescode = String.valueOf(code);
		
		try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
			StringBuilder response = new StringBuilder();
			String responseLine = null;
			while ((responseLine = br.readLine()) != null) {
				response.append(responseLine.trim());
			}
			resultJson = response.toString();
		}
		
		} catch (Exception e) {
			e.printStackTrace();
		}

:star_struck:thanks for tutorials/PostJSONWithHttpURLConnection.java at master · eugenp/tutorials · GitHub

did anyone solve it this way…
sorry if there is a mistake :smile:

Thanks & Regards
Maman H

1 Like

thanks for the directions

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.