I am AN ABSOLUTE C# NOOB, so this is my very first project. I am write a C% command line program that I input a URL it downloads images from a gallery website I frequent. 99% of the the code I have written works. My only issue is sometimes my code, when trying to get the webpage source code, sometimes the download fails. 99% of what I am doing works. This 1% sometimes makes my program crash. I am trying to find a way to make WebClient.DownloadString will retry to download the page source if there is an error. With all that said above, 99% of the code is written, and working, so I will not rewrite it from the ground up in a different version of .net. (A suggestion I saw in a discord channel dedicated to C# coding that was not helpful in the least)
This is the code I have for downloading the page source:
static string getPageSource(string url)
{
string pageSource = "";
WebClient client = new WebClient();
pageSource = client.DownloadString(url);
if(pageSource.Length == 0)
{
pageSource = client.DownloadString(url);
}
return pageSource;
}
The code itself functions as is. Just whenever it fails, the app crashes.
YoItsTrev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3