以下引自msdn:
Console.Write("\nPlease enter the URL to post data to : ");
String uriString = Console.ReadLine();// Create a new WebClient instance.
WebClient myWebClient = new WebClient();Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URL");
string fileName = Console.ReadLine();Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);
// Upload the file to the URL using the HTTP 1.0 POST.
byte[] responseArray = myWebClient.UploadFile(uriString,"POST",fileName);// Decode and display the response.
Console.WriteLine("\nResponse Received.The contents of the file uploaded are: \n{0}",Encoding.ASCII.GetString(responseArray));
Console.Write("\nPlease enter the URL to post data to : ");
String uriString = Console.ReadLine();// Create a new WebClient instance.
WebClient myWebClient = new WebClient();Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URL");
string fileName = Console.ReadLine();Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);
// Upload the file to the URL using the HTTP 1.0 POST.
byte[] responseArray = myWebClient.UploadFile(uriString,"POST",fileName);// Decode and display the response.
Console.WriteLine("\nResponse Received.The contents of the file uploaded are: \n{0}",Encoding.ASCII.GetString(responseArray));
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货