c#

C#中GET请求可以下载文件吗

小樊
125
2024-07-18 19:01:30
栏目: 编程语言

是的,C#中可以通过GET请求下载文件。可以使用System.Net.WebClient类来发送GET请求并下载文件。以下是一个示例代码:

using System;
using System.Net;

class Program
{
    static void Main()
    {
        string fileUrl = "https://example.com/examplefile.txt";
        string savePath = @"C:\Downloads\examplefile.txt";

        WebClient client = new WebClient();
        client.DownloadFile(fileUrl, savePath);

        Console.WriteLine("File downloaded successfully.");
    }
}

在上面的示例中,我们使用WebClient类发送GET请求并下载文件。您可以将文件的URL和保存路径替换为实际的文件URL和本地保存路径。运行该代码后将会下载文件到指定的保存路径。

0
看了该问题的人还看了