I am getting http status codes for urls using jsoup as follows:
Connection.Response response = null
Document doc = Jsoup.connect(url).ignoreContentType(true).get()
response = Jsoup.connect(url)
.userAgent("Mozilla/5.0 (X11 Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")
.timeout(10000)
.execute()
int statusCode = response.statusCode()
if (statusCode == 200)
urlExists = true
else
urlExists = false
Basically, I want to check if the url specified is returning 200 status code or not i.e. if its a html page, does it exist or if its a pdf file, does it exist and so on. It does not work for urls ending in .jpg because jpg files cannot be parsed by jsoup. I am using jsoup in conjunction with crawler4j. Is there any other way i can find the http status code for all the urls. My urls end in following extensions:
css js pdf zip rar tar png gif html