下载文件
作者:互联网
//添加地址
HttpWebRequest requestUrl = (HttpWebRequest)WebRequest.Create(url);
requestUrl.Method = "GET";
requestUrl.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
requestUrl.Headers.Add("Accept-Language", "zh-CN,zh;q=0.9");
requestUrl.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1";
HttpWebResponse responseUrl = (HttpWebResponse)requestUrl.GetResponse();
string urlRe = responseUrl.ResponseUri.ToString();
//模拟请求视频
HttpWebRequest requesturlRe = (HttpWebRequest)WebRequest.Create(urlRe);
HttpWebResponse responseurlRe = (HttpWebResponse)requesturlRe.GetResponse();
Stream myResponseStream = responseurlRe.GetResponseStream();
resp.Content = new StreamContent(myResponseStream);
resp.Content.Headers.ContentType = new MediaTypeHeaderValue("video/mp4");
//设置文件下载
resp.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = System.Web.HttpUtility.UrlEncode("yxt_" + dyvideomodel.aweme_id + ".mp4", System.Text.Encoding.UTF8)
};
return resp;
标签:文件,requestUrl,resp,HttpWebResponse,Headers,HttpWebRequest,new,下载 来源: https://www.cnblogs.com/yutang-wangweisong/p/14344004.html