網路流不支援查詢長度,處理方法GetResponseStream
阿新 • • 發佈:2019-01-25
string fullRoad = Configuration.MessageFileDownLoad + road;
string fileName = Path.GetFileName(fullRoad);
byte[] byteFile = null;
Uri uri = new Uri(fullRoad);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
List<byte> bytes = new List<byte>();
int temp = stream.ReadByte();
while (temp != -1)
{
bytes.Add((byte)temp);
temp = stream.ReadByte();
}
Response.Clear();
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
Response.BinaryWrite(byteFile);
Response.End();
string fileName = Path.GetFileName(fullRoad);
byte[] byteFile = null;
Uri uri = new Uri(fullRoad);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
List<byte> bytes = new List<byte>();
int temp = stream.ReadByte();
while (temp != -1)
{
bytes.Add((byte)temp);
temp = stream.ReadByte();
}
byteFile = bytes.ToArray();
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
Response.BinaryWrite(byteFile);
Response.End();