I am extracting details from a website using the below code.
Code:
private class FetchAllData extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
Utilities.custom_toast(CurrentResult.this, "Refreshing", "gone!", "short", "vertical");
}
@Override
protected Void doInBackground(Void... params)
{
try
{
//String urlX = URL1 + "?x=" + new Random().nextInt(100000); //Method1
String urlX = URL1 //Method2;
URL url = new URL(""+ urlX);
URLConnection con = url.openConnection();
con.setUseCaches(false); //This will stop caching!
// BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
PageCode = "";
OriginalPageCode = "";
while ((inputLine = in.readLine()) != null)
{
PageCode += inputLine;
}
OriginalPageCode = PageCode;
toast_IshtmlObtained = urlX+ "\nHTML success obtained as follows:\n\n";
try
{
extract_website_and_save();
toast_IsInfoExtracted = "success extracting website";
}
catch (Exception e1)
{
toast_IsInfoExtracted = "error extracting website";
}
in.close();
}
catch (Exception e)
{
PageCode = "ERROR: " + e;
toast_IshtmlObtained = "HTML not obtained:\nHTML retrieved as follows:" + PageCode;
}
return null;
}
@Override
protected void onPostExecute(Void result)
{
Utilities.custom_toast(CurrentResult.this, "Done", "gone!", "short", "vertical");
setText();
......
}
}
Question:
Beforehand I was using the URL in Method1 and was successful to access and extract the website details. However, in these days it does not work. I now tried Method2 and it works now.
I would like to ask if the random number in Method1 is important if the number of users accessing to the website is enormous, and any drawback if using the direct URL as in Method2? Thanks.
Aucun commentaire:
Enregistrer un commentaire