I'd like to only get page headers for a url without downloading the page content. This is what I'm using right now:
...
URL targetUrl = new URL( urlValue );
HttpURLConnection conn = (HttpURLConnection) targetUrl.openConnection();
String value = conn.getHeaderField(0);
...
I'm not sure if this is getting the headers then quitting or what its doing.
Send a HEAD request instead of a GET request (which is the default method).
conn.setRequestMethod("HEAD");
// ...
Otherwise the full response body is been returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With