Please tell me why the following error occurs

private string[] DownloadFileFromServer(string from, string to)// Функция #1 { // try // { using (WebClient client = new WebClient()) { client.DownloadFile(from , to); } string[] file = File.ReadAllLines(to); File.Delete(to); return file; // } // catch { MessageBox.Show("Отсутствует соединение с сервером. Программа закрывается"); Application.Exit(); return null; } } 

` enter image description here

    2 answers 2

    An HTTP 404 error returned by the server indicates that the resource you are requesting is not found.

    Make sure that the from argument that is passed to the DownloadFileFromServer method contains the address of an existing resource. For the test, try copying this address into the browser and downloading the file with it.

    • The program works stably at first, an error occurs only after some time in the process of work, the file addresses are all correct - ZOOM SMASH

    The exception contains the 404 server error code.

    In short, this means (quote from Wikipedia):

    When communicating via HTTP, the client requires an answer to its request to the server. For example, a web browser requests an HTML document (web page) and expects a numeric response code and, not always, a message. In code 404, the first digit “4” indicates a customer error, for example, a typo in the URL. The next two digits indicate the specific error. HTTP uses three-digit codes that resemble codes for earlier versions of the FTP and NNTP protocols.

    Following the response code 404 for a human understanding is an explanation of the reason. The HTTP specification offers the phrase “Not Found” (not found) and most web servers by default display HTML pages that include both 404 code and the phrase “Not Found”.

    Error 404 is often returned when the page has been moved or deleted, or the file name in the code and on the server does not match. In the first case, it is better to return the client code 301 Moved Permanently, which can be configured in the configuration of most servers, or redirect to another URL. In the second case, it is better to return the code 410 Gone. However, since these two options require special server configuration, most websites do not use them.

    Error 404 should not be confused with the error DNS, which appears when this URL refers to the name of a nonexistent server. Error 404 means that the server itself was found, but could not find the requested page.

    Those. the error is either on your side (invalid link) or on the server side (since the last request, the page has changed the address).

    • Links are all correct - ZOOM SMASH
    • @ZOOMSMASH, then it's up to the server. User-Agent set ?, cookies - allowed? It does not happen that the server is just football. - Align
    • @ZOOMSMASH, there is still a moment with downloading files. There should be a direct link to the file! There are also all kinds of protection against automatic downloading of files, which, for example, require JavaScript and give a direct link only after the JS function is executed. - Align
    • User-agent no - ZOOM SMASH
    • @ZOOMSMASH, try setting the data, see which link. Here only by trial and error to identify the cause. - Align