From d3266109e296abd22d65bc240457bebd75b226bc Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 14 七月 2020 11:05:47 +0800
Subject: [PATCH] 2020-7-14-1

---
 ZigbeeApp/Shared/Phone/Device/Logic/Send.cs |   51 ++++++++++++++++++++++++++++++---------------------
 1 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs
index 35b7328..d185dd6 100644
--- a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs
+++ b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs
@@ -1238,35 +1238,44 @@
         /// <returns></returns>
         public static async System.Threading.Tasks.Task<string> HttpWebRequest(string getUrl, string str, string method, int second = 3, bool _bool = false)
         {
+
             HttpWebRequest request = WebRequest.Create(getUrl) as HttpWebRequest; //鍒涘缓璇锋眰
             request.Method = method; //璇锋眰鏂瑰紡涓篜OST/GET
-            request.ContentType = "application/json"; 
+            request.ContentType = "application/json";
             request.Timeout = second * 1000;//瓒呮椂鏃堕棿
-            if (_bool) {
-                //鐢ㄤ簬楂樿儨鍙瀵硅鎺ュ彛
-                request.Headers.Add("Authorization", Config.Instance.Token);
-            }
-            if (method == "POST")
-            {
-                byte[] jsonbyte = System.Text.Encoding.UTF8.GetBytes(str);
-                request.ContentLength = jsonbyte.Length;
-                Stream postStream = request.GetRequestStream();
-                postStream.Write(jsonbyte, 0, jsonbyte.Length);
-                postStream.Close();
-            }
-            //鍙戦�佽姹傚苟鑾峰彇鐩稿簲鍥炲簲鏁版嵁       
-            HttpWebResponse res;
             try
             {
-                res = (HttpWebResponse)request.GetResponse();
+                if (_bool)
+                {
+                    //鐢ㄤ簬楂樿儨鍙瀵硅鎺ュ彛
+                    request.Headers.Add("Authorization", Config.Instance.Token);
+                }
+                if (method == "POST")
+                {
+                    byte[] jsonbyte = System.Text.Encoding.UTF8.GetBytes(str);
+                    request.ContentLength = jsonbyte.Length;
+                    Stream postStream = request.GetRequestStream();
+                    postStream.Write(jsonbyte, 0, jsonbyte.Length);
+                    postStream.Close();
+                }
+                //鍙戦�佽姹傚苟鑾峰彇鐩稿簲鍥炲簲鏁版嵁       
+                HttpWebResponse res;
+                try
+                {
+                    res = (HttpWebResponse)request.GetResponse();
+                }
+                catch (WebException ex)
+                {
+                    res = (HttpWebResponse)ex.Response;
+                }
+                StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
+                string content = sr.ReadToEnd(); //鑾峰緱鍝嶅簲瀛楃涓�
+                return content;
             }
-            catch (WebException ex)
+            catch
             {
-                res = (HttpWebResponse)ex.Response;
+                return null;
             }
-            StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
-            string content = sr.ReadToEnd(); //鑾峰緱鍝嶅簲瀛楃涓�
-            return content;
         }
         /// <summary>
         /// 璇锋眰鏈嶅姟鍣ㄧ殑鏂规硶

--
Gitblit v1.8.0