How to effectively check if an HTTP response contains HTML or not in Java? I am making an HTTP connection like shown below:
URL url = new URL(inputURL);
con = (HttpsURLConnection)url.openConnection(proxy);
con.setRequestMethod(request.getMethod());
con.connect();
con.getResponseCode();
Is there a way to effectively check if the response contains HTML (and not other resources like image,.css or .js files).
You have a method dedicated to this : getContentType
On your HttpsURLConnection, it returns the mime type of the received file.
For an HTML file, it would be “text/html”.
So you can just check :