Answer the question
In order to leave comments, you need to log in
how to make a get request java?
URL url = new URL(urlAdress);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.disconnect();
Answer the question
In order to leave comments, you need to log in
The answer to your question is easily found by a search engine.
Here is an example:
https://www.baeldung.com/java-http-request
Here is an example code. Just handle exceptions and tweak for yourself
public class Main {
public static void main(String[] args) {
final String urlAdress = "http://example.com"; // url куда нужно совершить запрос
URL url = new URL(urlAdress);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
int status = con.getResponseCode(); // совершаем запрос
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); // читаем ответ
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
con.disconnect();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question