溫馨提示×

C# webclient能上傳文件嗎

c#
小樊
215
2024-07-12 20:52:27
欄目: 編程語言

是的,C#中的WebClient類可以用來上傳文件??梢允褂肬ploadFile或UploadData方法來上傳文件到服務器。以下是一個示例代碼:

using System;
using System.Net;

class Program
{
    static void Main()
    {
        WebClient client = new WebClient();
        string filePath = "C:\\path\\to\\file.txt";
        string uploadUrl = "http://example.com/upload";

        client.UploadFile(uploadUrl, filePath);
        Console.WriteLine("File uploaded successfully.");
    }
}

在上面的示例中,我們創建了一個WebClient對象,并使用UploadFile方法將文件上傳到指定的URL。您可以根據需要修改文件路徑和上傳URL。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女