I have requirement to post a soap xml to a POST endpoint. But before posting, I need to do a health check of that url or find the status of that url. I tried to do an HttpURLConnection 'GET' method, but the url does not support 'GET'. Please help!
Asked
Active
Viewed 1,186 times
0
-
1If you are using springboot then you can use actuator to check health check – GauravRai1512 Sep 24 '19 at 10:40
-
No this is a simple web application. – manjosh Sep 24 '19 at 10:57
-
1"but the url does not support" If you are using an API provided by someone else, you will have to consult the documentation of that API to determine how to check the health of that server. There is no standardised means of checking the health of an HTTP service. – Raedwald Sep 26 '19 at 11:11
1 Answers
1
As you said yourself in the question that method is POST and not GET. So sending a GET request is irrelevant (regardless of whether it works or not). You can send a POST request using HttpURLConnection. But you will have to read and learn how to properly do it. The lazy way is to use a 3d party HttpClient. Here are a few options:
- Apache HttpClient - a very widely used library
- OK HttpClient - Open Source library
- And my favorite (Open Source library written by me) MgntUtils library
With MgntUtils library your code could be as simple as
private static void testHttpClient() {
HttpClient client = new HttpClient();
client.setContentType("application/json; charset=utf-8");
client.setConnectionUrl("http://www.your.url.com/");
String content = null;
try {
content = client.sendHttpRequest(HttpMethod.POST);
} catch (IOException e) {
content = TextUtils.getStacktrace(e, false);
}
System.out.println(content);
}
Here is Javadoc for MgntUtils HTTPClient class. The library itself could be found here as Maven artifacts or on Git (including sources and JavaDoc). An article about the library (although it doesn't describe HttpClient feature) could be found here

Michael Gantman
- 7,315
- 2
- 19
- 36