public UploadStringAsync ( System address, string data ) : void | ||
address | System | |
data | string | |
return | void |
using System.Net; string myJson = "{ \"name\": \"John\", \"age\": 30 }"; string url = "https://www.example.com/api/user"; WebClient client = new WebClient(); client.UploadStringCompleted += (s, e) => { if (e.Error != null) { Console.WriteLine("Error: " + e.Error.Message); return; } Console.WriteLine("Response: " + e.Result); }; client.UploadStringAsync(new Uri(url), "POST", myJson);
using System.Net; NameValueCollection data = new NameValueCollection(); data["name"] = "John"; data["age"] = "30"; string url = "https://www.example.com/api/user"; WebClient client = new WebClient(); client.UploadValuesCompleted += (s, e) => { if (e.Error != null) { Console.WriteLine("Error: " + e.Error.Message); return; } Console.WriteLine("Response: " + Encoding.UTF8.GetString(e.Result)); }; client.UploadValuesAsync(new Uri(url), "POST", data);In this example, form data is uploaded to a server using the WebClient.UploadValuesAsync method. The response from the server is printed to the console. The System.Net.WebClient namespace is part of the .NET Framework Class Library.
public UploadStringAsync ( System address, string data ) : void | ||
address | System | |
data | string | |
return | void |