1 public class UpLoadFile 2 { 3 public static void UpLoadFiles(string fileName) 4 { 5 string fileType = Path.GetExtension(fileName); 6 string upLoadParms = "?Service=notify" + "&fileType=" + fileType; 7 WebRequest webRequest = HttpWebRequest.Create(new Uri("http://192.168.0.1:8080" + upLoadParms)); 8 System.Text.Encoding coding = System.Text.Encoding.UTF8; 9 webRequest.ContentType = "application/x-www-form-urlencoded"; 10 webRequest.Method = "POST"; 11 System.IO.Stream requeStream = webRequest.GetRequestStream(); 12 FileStream fileStream=new FileStream(fileName,FileMode.Open,FileAccess.Read); 13 BinaryReader binaryReader=new BinaryReader(fileStream,coding); 14 byte[] buffer = binaryReader.ReadBytes((int) fileStream.Length); 15 requeStream.Write(buffer,0,buffer.Length); 16 fileStream.Close(); 17 requeStream.Close(); 18 System.Net.WebResponse response = webRequest.GetResponse(); 19 Stream responseStream = response.GetResponseStream(); 20 StreamReader streamReader = new StreamReader(responseStream); 21 string returnVal = streamReader.ReadToEnd(); 22 responseStream.Close(); 23 response.Close(); 24 25 } 26 }
时间: 2024-11-03 22:44:55