Above is my code i have written to hit a web service whose endpoint is expecting a Byte Stream object. I am able to do that but i am not getting any response. I have to test the response. Though i am getting 200 ok but a string is sent in response that i am not getting.
How can I get the response ?
return
keywordMinimal working code is below, adjust as per your needs:
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
URL url = new URL("http://example.com");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
String response = IOUtils.toString(con.getInputStream(), StandardCharsets.UTF_8);
return response;