You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HttpGetFileRequest.cs 1.1 KiB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4. using Learun.Util;
  5. namespace Learun.Application.WeChat
  6. {
  7. class HttpGetFileRequest : IHttpSend
  8. {
  9. public string Send(string url, string path)
  10. {
  11. Dictionary<string, string> header;
  12. var bytes = new HttpHelper().GetFile(url, out header);
  13. if (header["Content-Type"].Contains("application/json"))
  14. {
  15. return Encoding.UTF8.GetString(bytes);
  16. }
  17. else
  18. {
  19. Regex regImg = new Regex("\"(?<fileName>.*)\"", RegexOptions.IgnoreCase);
  20. MatchCollection matches = regImg.Matches(header["Content-disposition"]);
  21. string fileName = matches[0].Groups["fileName"].Value;
  22. string filepath = path.TrimEnd('\\') + "\\" + fileName;
  23. System.IO.Stream so = new System.IO.FileStream(filepath, System.IO.FileMode.Create);
  24. so.Write(bytes, 0, bytes.Length);
  25. so.Close();
  26. }
  27. return header.ToJson();
  28. }
  29. }
  30. }