ASPNET中利用WebClient上传图片到远程服务的方法
来源:诚信在线    发布时间:2017-07-01 15:08:42

  var webclient = new WebClient();

  }

  {

  string postData = "data=" + HttpUtility.UrlEncode(Convert.ToBase64String(b));

  }

  2.后盾

  ms = null;

  System.IO.Stream fs = (System.IO.Stream)oFiles[0].InputStream;

  1.页面

  }

  System.IO.FileStream fs = new System.IO.FileStream(context.Server.MapPath("~/") + "/收集图片/" + filename, System.IO.FileMode.Create);

  msg = "{\"code\":\"上传的文件不是图片\"}";

  Response.Write(msg);

  fileextension = "bmp";

  {

  string FileName = FilePath.Substring(FilePath.LastIndexOf("\\") + 一);

  }

  else if (fileextension == "6677")

  byte[] filedata = Convert.FromBase64String(context.Request["data"]);

  fs.Read(b, 0, oFiles[0].ContentLength);

  else if (fileextension == "255216")

  catch (Exception exe)

  {

  {

  }

  string msg = "";

  fileextension = "jpg";

  {

  1、客户端

  {

  fileextension = "tif";

  fileextension = "png";

  webclient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

  ms.Close();

  }

  byte[] buffer = webclient.UploadData("http://localhost/datapush/WebServiceDataPush.asmx/DataPush", "POST", byteArray);//asmx

  }

  {

  以上所述是小编给各人先容的ASP.NET外哄骗WebClient上传图片到近程效劳的要领,进展对于各人有所协助,若是人人有任何疑难请给尔留言,小编会实时复兴各人的。正在此也特别很是感激各人对于剧本之野网站的支撑!

  {

  byte[] b = new byte[oFiles[0].ContentLength];

  System.Web.HttpFileCollection oFiles = System.Web.HttpContext.Current.Request.Files;

  2、服务端

  if (filedata.Length == 0)

  var msg = Encoding.UTF8.GetString(buffer);

  if (filedata.Length > 1048576)

  {

  fs.Close();

  msg = "{\"code\":\"上传图片乐成\"}";

  }

  string fileextension = filedata[0].ToString() + filedata[一].ToString();

  }

  byte[] byteArray = Encoding.UTF8.GetBytes(postData);

  //byte[] buffer = webclient.UploadData("http://localhost/datapush/DataPush.ashx", "POST", byteArray);//ashx

  else

  fileextension = "gif";

  if (fileextension == "7173")

  else if (fileextension == "13780")

  msg = "{\"code\":\"图片大小不能超过一M\"}";

  string filename = Guid.NewGuid().ToString("D") + "." + fileextension;

  fs = null;

  else if (fileextension == "7373")

  string FilePath = oFiles[0].FileName;

  System.IO.MemoryStream ms = new System.IO.MemoryStream(filedata);

  msg= "{\"code\":\"上传的是空文件\"}";

  ms.WriteTo(fs);

  msg = "{\"code\":\"" + exe.Message + "\"}";

  {

  }

  try

  //留存图片

  你大概感兴趣的文章:silverlight用webclient年夜文件上传的实例代码C# WebClient类用法实例C#外正在WebClient外运用post发送数据完成要领Silverlight外同步挪用WebClient的解决办法,是同步!用WebClient.UploadData要领上载文件数据的法子


诚信在线 除注明原创以外,其余均来自互联网以及微信朋友圈,如有侵权请联系站长立即删除!
文章地址:http://www.my517517.com/YY/20170701389.html



上一篇:ASPNET实现单点登陆SSO适用于多种情况 下一篇:正则删除字符串左、右或两端的空格经验总结