Suppress save / dialog in web browser and automate download

I want to automate the exe download requested by the link from the client side. I can get the first redirected link from http://go.microsoft.com/fwlink/?LinkID=149156 at http://www.microsoft.com/getsilverlight/handlers/getsilverlight.ashx . Please click and check how it works. fwlink β†’ .ashx β†’ .exe ... I want to get a direct link to .exe. But the answer returns 404 when the web handler requests through the code, but if you try the browser, it will actually load. Can anyone suggest how to automate the download of the above link? The code I use to redirect the link is this.

public static string GetLink(string url) { HttpWebRequest httpWebRequest = WebRequest.Create(url) as HttpWebRequest; httpWebRequest.Method = "HEAD"; httpWebRequest.AllowAutoRedirect = false; // httpWebRequest.ContentType = "application/octet-stream"; //httpWebRequest.Headers.Add("content-disposition", "attachment; filename=Silverlight.exe"); HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse; if (httpWebResponse.StatusCode == HttpStatusCode.Redirect) { return httpWebResponse.GetResponseHeader("Location"); } else { return null; } } 
0
source share
1 answer

Just test this and it will download the file.

 WebClient client = new WebClient(); client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); client.DownloadFile(url, "Filename.exe"); 

You just needed to add a user agent, since the specific silverlight load depends on which browser you are running on, therefore, if it cannot detect it, it will fail.

Change the user agent to the one you want to load.

+2
source

Source: https://habr.com/ru/post/1490447/


All Articles