.net core 使用远程地址获取文件流

/// <summary>
/// 用远程地址获取文件流
/// </summary>
/// <param name="path">URL</param>
/// <returns></returns>
private byte[] GetUrlMemoryStream(string path)
{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(path);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();

List<byte> btlst = new List<byte>();
int b = responseStream.ReadByte();
while (b > -1)
{
btlst.Add((byte)b);
b = responseStream.ReadByte();
}
byte[] bts = btlst.ToArray();
return bts;
}

 

posted on 2020-05-13 16:32  A菜鸟  阅读(2344)  评论(0编辑  收藏  举报