/**////<summary> /// 使用WebClient上传文件测试 ///</summary> publicclass WebClientTest { publicstaticvoid Main(string[] args) { // Server URL string uriString ="http://localhost/FileUpLoad/002.gif"; // Local Directory File Info string fileName =@"c:/temp/002.gif"; // Create a new WebClient instance. WebClient myWebClient =new WebClient(); 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)); //Waite for User Console.ReadLine(); } }
/**////<summary> /// 使用WebClient上传文件测试 ///</summary> publicclass WebClientTest { publicstaticvoid Main(string[] args) { // Server URL string uriString ="http://localhost/FileUpLoad/002.gif"; // Local Directory File Info string fileName =@"c:/temp/002.gif"; // Create a new WebClient instance. WebClient myWebClient =new WebClient(); 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,"PUT",fileName); // Decode and display the response. Console.WriteLine("/nResponse Received.The contents of the file uploaded are: /n{0}",Encoding.ASCII.GetString(responseArray)); //Waite for User Console.ReadLine(); } }