A
A
Anton Rodionov2021-10-27 20:25:18
C++ / C#
Anton Rodionov, 2021-10-27 20:25:18

How to download a file not from a direct link?

There is an indirect link to the file. When you click on it, the browser starts downloading the file. If you use WebRequest, the file does not download, a page appears with something like this: "This document is a web page in a single file, also called a web archive file. If you see this message, this browser or editor does not support web archive files Download a browser that supports web archives, such as Microsoft Internet Explorer."
If you use WebBrowser, then a dialog box pops up where to save the file that you need to bypass. How to download it?
If you look at the response from the server to the request, it looks like this:
61798cbc5c9d8150589945.png

UPD: It
was not possible to solve it using standard methods, I had to use a third-party RestSharp library.
Here is the code that now downloads the file:

IRestRequest request = new RestRequest("?savertf=&vkart=card&nd=602481428&rdk=&firstDoc=1&link_id=0&intelsearch=&page=all");
            var client = new RestClient("http://pravo.gov.ru/proxy/ips/");
            byte[] response = client.DownloadData(request);
            File.WriteAllBytes("123.rtf", response);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question