How to be sure that downloaded html source code is from specific website?

BrentNewhall

New Member
So I have a service that downloads html source code of certain website and then compares it to the previously downloaded one from the same website, to see if any changes have occured.The problem I had yesterday: I was connected to WiFi in public and my service started downloading the code, since it wasn't showing that there's no connection. But you first have to login when using public WiFi so it was redirected to their login page and my service downloaded the html code of a login page.How can I surely get the source code of the site I want?EDIT: here's the source code (btw I turn source code into md5 for easier comparison but it's not important):\[code\]public class DownloadHandler{public String getMd5(String url){ HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpResponse response = null; try { response = client.execute(request); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } InputStream in = null; try { in = response.getEntity().getContent(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { str.append(line); } } catch (IOException e) { e.printStackTrace(); } try { in.close(); } catch (IOException e) { e.printStackTrace(); } String html = str.toString(); try { String md5 = stringToMd5(html); return md5; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; }}public String stringToMd5(String s) throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5");stringa md5.update(s.getBytes(), 0, s.length()); String md5String = new BigInteger(1, md5.digest()).toString(16); return md5String;}\[/code\]And the function to check connection:\[code\]boolean isNetworkAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager .getActiveNetworkInfo(); return activeNetworkInfo != null;}\[/code\]
 
Back
Top