Prechádzať zdrojové kódy

添加获取网络文件流方法

lcl 1 rok pred
rodič
commit
b6cb9aba41
1 zmenil súbory, kde vykonal 41 pridanie a 0 odobranie
  1. 41 0
      Util/PublicFunction.cs

+ 41 - 0
Util/PublicFunction.cs

@@ -233,5 +233,46 @@ namespace MySystem
             return decimal.Parse(str);
         }
     
+
+
+
+
+        #region 获取网络文件内容
+
+        public static string GetNetFileContent(string url)
+        {
+            string textContent = "";     
+            using (var client = new System.Net.WebClient())
+            {
+                try
+                {
+                    textContent = client.DownloadString(url); // 通过 DownloadString 方法获取网页内容
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "获取网络文件内容异常");
+                }
+            }
+            return textContent;
+        }
+
+        public static byte[] GetNetFileData(string url)
+        {
+            byte[] textContent = new byte[] { };
+            using (var client = new System.Net.WebClient())
+            {
+                try
+                {
+                    textContent = client.DownloadData(url); // 通过 DownloadString 方法获取网页内容
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "获取网络文件流异常");
+                }
+            }
+            return textContent;
+        }
+
+        #endregion
     }
 }