Reputation: 734
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!
Upvotes: 0
Views: 1710
Reputation: 7808
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:
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
Upvotes: 1