/// <Summary> /// The network path to save the file to byte [], saved locally /// </ Summary> /// <param name = "zjkurl"> </ param> public void UrlToByte ( String zjkurl) { the HttpWebRequest REQ = (the HttpWebRequest) HttpWebRequest.Create (zjkurl); req.Method = " the GET " ; the using (WR = the WebResponse req.GetResponse ()) { the StreamReader responseStream = new new the StreamReader (wr.GetResponseStream (), Encoding. UTF8); int length = (int)wr.ContentLength; byte[] bs = new byte[length]; HttpWebResponse response = wr as HttpWebResponse; Stream stream = response.GetResponseStream(); //读取到内存 MemoryStream stmMemory = new MemoryStream(); byte[] buffer1 = new byte[length]; int i; while ((i = stream.Read(buffer1, 0, buffer1.Length)) > 0) { stmMemory.Write(buffer1, 0, i); } byte[] arraryByte = stmMemory.ToArray(); stmMemory.Close(); //保存到本地 string path = Server.MapPath(@"\a.jpg"); FileStream fs = new FileStream(path, FileMode.Create); fs.Write(arraryByte, 0, arraryByte.Length); fs.Dispose(); } }