Junior — Middle
Have you created or sent requests to external or internal services in your work?
sobes.tech AI
Answer from AI
Yes, in my work I had to create and send requests to external and internal services. For example, to integrate with REST API, I used HTTP clients such as HttpURLConnection or libraries like Apache HttpClient to send GET, POST requests and receive responses. This allows interaction with other systems, retrieving data or invoking remote functions.
Example of sending a GET request using HttpURLConnection:
URL url = new URL("https://api.example.com/data");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
int status = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
con.disconnect();
System.out.println(content.toString());