web文件上传,webapi后台接收

后台:

        public string Post()
        {
            string key = HttpContext.Current.Request["key"];
            string value = HttpContext.Current.Request["value"];
            HttpFileCollection files = HttpContext.Current.Request.Files;

            foreach (string f in files.AllKeys)
            {
                HttpPostedFile file = files[f];
                if (string.IsNullOrEmpty(file.FileName) == false)
                    file.SaveAs(HttpContext.Current.Server.MapPath("~/App_Data/") + file.FileName);
            }

            return key + value;
        }

前端:




    
    


    





你可能感兴趣的:(C#随记,mvc,web,api)