标签:log system path www. 发送 using try mat class
/// <summary> /// 发送文件 /// </summary> public static void PostBinaryData() { string notice = Convert.ToString(Guid.NewGuid()); string sign = MD5Helper.Encrypt("zoversoft" + notice); string url = string.Format("http://www.xx.com/File/SaveImageData?childFile={0}&sign={1}¬ice={2}", "lk", sign, notice); byte[] bytes = System.IO.File.ReadAllBytes(@"F:\微信应用logo\消息.jpg"); HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(url); wRequest.ContentType = "multipart/form-data"; wRequest.ContentLength = bytes.Length; wRequest.Method = "POST"; using (Stream stream = wRequest.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); using (HttpWebResponse wResponse = (HttpWebResponse)wRequest.GetResponse()) { using (StreamReader sReader = new StreamReader(wResponse.GetResponseStream(), System.Text.Encoding.UTF8)) { Console.Write(sReader.ReadToEnd()); Console.ReadKey(); } } } }
/// <summary> /// 接收文件 /// </summary> /// <param name="childFile">文件夹</param> /// <param name="sign">签名</param> /// <param name="notice">随机字符串</param> /// <returns>结果/文件路径</returns> [HttpPost] public JsonResult SaveImageData(string childFile, string sign, string notice) { try { if (MD5Helper.Encrypt("zoversoft" + notice) == sign) { string filePath = IPublicVar.WebDownPath + childFile; if (System.IO.Directory.Exists(filePath) == false) { System.IO.Directory.CreateDirectory(filePath); } string fileName = string.Format("{0:yyyyMMdd}", DateTime.Now) + sign + ".jpg"; using (Bitmap img = new Bitmap(Request.InputStream)) { img.Save(filePath + @"\" + fileName); return Json(childFile + "/" + fileName); } } else { return Json("0"); } } catch { return Json("-1"); } }
标签:log system path www. 发送 using try mat class
原文地址:https://www.cnblogs.com/5tomorrow/p/10223899.html