winform 使用 webclient 上传
public void ProcessRequest(HttpContext context) { HttpPostedFile file = context.Request.Files[0]; file.SaveAs(context.Server.MapPath("~/uploadimages/") + file.FileName); }
string strurl = "http://localhost/Provider/HandlerUpImage.ashx"; WebClient webclient = new WebClient(); byte[] buffer = webclient.UploadFile(strurl, "POST", @"C:\a.txt"); using (FileStream fs = new FileStream(@"C:\a.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Write(buffer, 0, buffer.Length); }