using System.Net; // Create a WebClient instance using WebClient client = new WebClient(); // Set the URI to upload the file string uri = "http://example.com/upload"; // Set the file path string filePath = "C:/example.txt"; // Upload the file to the server client.UploadFile(uri, filePath);
using System.Net; using System.Text; // Create a WebClient instance using WebClient client = new WebClient(); // Set the URI to upload the file string uri = "http://example.com/upload"; // Set additional headers client.Headers.Add("Authorization", "Bearer token"); client.Headers.Add("Content-Type", "application/json"); // Set the file path string filePath = "C:/example.txt"; // Upload the file to the server with additional headers byte[] response = client.UploadFile(uri, filePath); // Convert response byte array to string string result = Encoding.UTF8.GetString(response);The System.Net.WebClient class is a part of the System.Net namespace in C#.