How to GET data from an URL and save it into a file in binary in C#.NET without the encoding mess?

前端 未结 3 769
悲&欢浪女
悲&欢浪女 2021-02-01 18:51

In C#.NET, I want to fetch data from an URL and save it to a file in binary.

Using HttpWebRequest/Streamreader to read into a string and saving using StreamWriter works

3条回答
  •  独厮守ぢ
    2021-02-01 19:32

    Minimalist answer:

    using (WebClient client = new WebClient()) {
        client.DownloadFile(url, filePath);
    }
    

    Or in PowerShell (suggested in an anonymous edit):

    [System.Net.WebClient]::WebClient
    $client = New-Object System.Net.WebClient
    $client.DownloadFile($URL, $Filename)
    

提交回复
热议问题