Requests via HTTPS (speaking of .NET WebClient)

Category : Geek

Actually I had some troubles today with a simply request downloading a file with the .NET WebClient class via https. Instead of http most webservers seem to expect an User-Agent header for security reasons when accessing the webserver through https.

The solution is just plain simple – add any random User-Agent header to the request otherwise the returned content or file is empty (0 bytes).

Dim oDownload As New WebClient
oDownload.Headers.Add(“User-Agent”, “Your App 1.0.0.0″)
oDownload.DownloadFile(“https://any.com/file.zip, “file.zip”)

I will not talk about the CustomSoapHeaders I was using. For the moment… it is a bit too late for in-depth programming details.

Note: WebClient class is available in the System.Net Namespace from .NET Framwork 2.0 and following.