using learun.util; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace learun.wechat { /// /// 版 本 EasyCode EC管理后台 /// Copyright (c) 2019-present EC管理有限公司 /// 创建人:tobin /// 日 期:2019.11.06 /// 描 述:get文件请求 /// public class HttpGetFileRequest : IHttpSend { /// /// /// /// /// /// public async Task Send(string url, string path) { var (by, header) = await new HttpHelper().GetFile(url); if (header["Content-Type"].Contains("application/json")) { return Encoding.UTF8.GetString(by); } else { Regex regImg = new Regex("\"(?.*)\"", RegexOptions.IgnoreCase); MatchCollection matches = regImg.Matches(header["Content-disposition"]); string fileName = matches[0].Groups["fileName"].Value; string filepath = path.TrimEnd('\\') + "\\" + fileName; System.IO.Stream so = new System.IO.FileStream(filepath, System.IO.FileMode.Create); so.Write(by, 0, by.Length); so.Close(); } return header.ToJson(); } } }