查看: 1896|回复: 0

[.NET开发] HttpHelper类的调用方法详解

发表于 2018-2-9 08:00:00

本文实例为大家分享了HttpHelper类的方法使用,供大家参考,具体内容如下

首先列出HttpHelper类

  1. /// <summary>
  2. /// Http操作类
  3. /// </summary>
  4. public class HttpHelper
  5. {
  6. private static log4net.ILog mLog = log4net.LogManager.GetLogger("HttpHelper");
  7. [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
  8. public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
  9. [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
  10. public static extern bool InternetGetCookie(string lpszUrlName, string lbszCookieName, StringBuilder lpszCookieData, ref int lpdwSize);
  11. public static StreamReader mLastResponseStream = null;
  12. public static System.IO.StreamReader LastResponseStream
  13. {
  14. get { return mLastResponseStream; }
  15. }
  16. private static CookieContainer mCookie = null;
  17. public static CookieContainer Cookie
  18. {
  19. get { return mCookie; }
  20. set { mCookie = value; }
  21. }
  22. private static CookieContainer mLastCookie = null;
  23. public static HttpWebRequest CreateWebRequest(string url, HttpRequestType httpType, string contentType, string data, Encoding requestEncoding, int timeout, bool keepAlive)
  24. {
  25. if (String.IsNullOrWhiteSpace(url))
  26. {
  27. throw new Exception("URL为空");
  28. }
  29. HttpWebRequest webRequest = null;
  30. Stream requestStream = null;
  31. byte[] datas = null;
  32. switch (httpType)
  33. {
  34. case HttpRequestType.GET:
  35. case HttpRequestType.DELETE:
  36. if (!String.IsNullOrWhiteSpace(data))
  37. {
  38. if (!url.Contains('?'))
  39. {
  40. url += "?" + data;
  41. }
  42. else url += "&" + data;
  43. }
  44. if(url.StartsWith("https:"))
  45. {
  46. System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
  47. ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
  48. }
  49. webRequest = (HttpWebRequest)WebRequest.Create(url);
  50. webRequest.Method = Enum.GetName(typeof(HttpRequestType), httpType);
  51. if (contentType != null)
  52. {
  53. webRequest.ContentType = contentType;
  54. }
  55. if (mCookie == null)
  56. {
  57. webRequest.CookieContainer = new CookieContainer();
  58. }
  59. else
  60. {
  61. webRequest.CookieContainer = mCookie;
  62. }
  63. if (keepAlive)
  64. {
  65. webRequest.KeepAlive = keepAlive;
  66. webRequest.ReadWriteTimeout = timeout;
  67. webRequest.Timeout = 60000;
  68. mLog.Info("请求超时时间..." + timeout);
  69. }
  70. break;
  71. default:
  72. if (url.StartsWith("https:"))
  73. {
  74. System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
  75. ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
  76. }
  77. webRequest = (HttpWebRequest)WebRequest.Create(url);
  78. webRequest.Method = Enum.GetName(typeof(HttpRequestType), httpType);
  79. if (contentType != null)
  80. {
  81. webRequest.ContentType = contentType;
  82. }
  83. if (mCookie == null)
  84. {
  85. webRequest.CookieContainer = new CookieContainer();
  86. }
  87. else
  88. {
  89. webRequest.CookieContainer = mCookie;
  90. }
  91. if (keepAlive)
  92. {
  93. webRequest.KeepAlive = keepAlive;
  94. webRequest.ReadWriteTimeout = timeout;
  95. webRequest.Timeout = 60000;
  96. mLog.Info("请求超时时间..." + timeout);
  97. }
  98. if (!String.IsNullOrWhiteSpace(data))
  99. {
  100. datas = requestEncoding.GetBytes(data);
  101. }
  102. if (datas != null)
  103. {
  104. webRequest.ContentLength = datas.Length;
  105. requestStream = webRequest.GetRequestStream();
  106. requestStream.Write(datas, 0, datas.Length);
  107. requestStream.Flush();
  108. requestStream.Close();
  109. }
  110. break;
  111. }
  112. //mLog.InfoFormat("请求 Url:{0},HttpRequestType:小贝,contentType:{2},data:{3}", url, Enum.GetName(typeof(HttpRequestType), httpType), contentType, data);
  113. return webRequest;
  114. }
  115. public static CookieContainer GetLastCookie()
  116. {
  117. return mLastCookie;
  118. }
  119. /// <summary>
  120. /// 设置HTTP的Cookie,以后发送和请求用此Cookie
  121. /// </summary>
  122. /// <param name="cookie">CookieContainer</param>
  123. public static void SetHttpCookie(CookieContainer cookie)
  124. {
  125. mCookie = cookie;
  126. }
  127. private static HttpWebRequest mLastAsyncRequest = null;
  128. public static HttpWebRequest LastAsyncRequest
  129. {
  130. get { return mLastAsyncRequest; }
  131. set { mLastAsyncRequest = value; }
  132. }
  133. /// <summary>
  134. /// 发送请求
  135. /// </summary>
  136. /// <param name="url">请求Url</param>
  137. /// <param name="httpType">请求类型</param>
  138. /// <param name="contentType">contentType:application/x-www-form-urlencoded</param>
  139. /// <param name="data">请求数据</param>
  140. /// <param name="encoding">请求数据传输时编码格式</param>
  141. /// <returns>返回请求结果</returns>
  142. public static string SendRequest(string url, HttpRequestType httpType, string contentType, string data, Encoding requestEncoding, Encoding reponseEncoding, params AsyncCallback[] callBack)
  143. {
  144. int timeout = 0;
  145. bool keepAlive = false;
  146. if (callBack != null && callBack.Length > 0 && callBack[0] != null)
  147. {
  148. keepAlive = true;
  149. timeout = 1000*60*60;
  150. mLog.Info("写入读取超时时间..." + timeout);
  151. }
  152. // mLog.Info("开始创建请求....");
  153. HttpWebRequest webRequest = CreateWebRequest(url, httpType, contentType, data, requestEncoding,timeout,keepAlive);
  154. string ret = null;
  155. // mLog.Info("创建请求结束....");
  156. if (callBack != null && callBack.Length > 0 && callBack[0] != null)
  157. {
  158. // mLog.Info("开始异步请求....");
  159. mLastAsyncRequest = webRequest;
  160. webRequest.BeginGetResponse(callBack[0], webRequest);
  161. }
  162. else
  163. {
  164. // mLog.Info("开始同步请求....");
  165. StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream(), reponseEncoding);
  166. ret = sr.ReadToEnd();
  167. sr.Close();
  168. }
  169. mLastCookie = webRequest.CookieContainer;
  170. //mLog.InfoFormat("结束请求 Url:{0},HttpRequestType:小贝,contentType:{2},结果:{3}", url, Enum.GetName(typeof(HttpRequestType), httpType), contentType,ret);
  171. return ret;
  172. }
  173. /// <summary>
  174. /// Http上传文件
  175. /// </summary>
  176. public static string HttpUploadFile(string url, string path)
  177. {
  178. using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
  179. {
  180. // 设置参数
  181. HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
  182. CookieContainer cookieContainer = new CookieContainer();
  183. request.CookieContainer = cookieContainer;
  184. request.AllowAutoRedirect = true;
  185. request.AllowWriteStreamBuffering = false;
  186. request.SendChunked = true;
  187. request.Method = "POST";
  188. request.Timeout = 300000;
  189. string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
  190. request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary;
  191. byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
  192. byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");
  193. int pos = path.LastIndexOf("\\");
  194. string fileName = path.Substring(pos + 1);
  195. //请求头部信息
  196. StringBuilder sbHeader = new StringBuilder(string.Format("Content-Disposition:form-data;name=\"file\";filename=\"{0}\"\r\nContent-Type:application/octet-stream\r\n\r\n", fileName));
  197. byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString());
  198. request.ContentLength = itemBoundaryBytes.Length + postHeaderBytes.Length + fs.Length + endBoundaryBytes.Length;
  199. using (Stream postStream = request.GetRequestStream())
  200. {
  201. postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
  202. postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
  203. int bytesRead = 0;
  204. int arrayLeng = fs.Length <= 4096 ? (int)fs.Length : 4096;
  205. byte[] bArr = new byte[arrayLeng];
  206. int counter = 0;
  207. while ((bytesRead = fs.Read(bArr, 0, arrayLeng)) != 0)
  208. {
  209. counter++;
  210. postStream.Write(bArr, 0, bytesRead);
  211. }
  212. postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
  213. }
  214. //发送请求并获取相应回应数据
  215. using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
  216. {
  217. //直到request.GetResponse()程序才开始向目标网页发送Post请求
  218. using (Stream instream = response.GetResponseStream())
  219. {
  220. StreamReader sr = new StreamReader(instream, Encoding.UTF8);
  221. //返回结果网页(html)代码
  222. string content = sr.ReadToEnd();
  223. return content;
  224. }
  225. }
  226. }
  227. }
  228. public static string HttpUploadFile(string url, MemoryStream files, string fileName)
  229. {
  230. using (MemoryStream fs = files)
  231. {
  232. // 设置参数
  233. HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
  234. CookieContainer cookieContainer = new CookieContainer();
  235. request.CookieContainer = cookieContainer;
  236. request.AllowAutoRedirect = true;
  237. request.AllowWriteStreamBuffering = false;
  238. request.SendChunked = true;
  239. request.Method = "POST";
  240. request.Timeout = 300000;
  241. string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
  242. request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary;
  243. byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
  244. byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");
  245. //请求头部信息
  246. StringBuilder sbHeader = new StringBuilder(string.Format("Content-Disposition:form-data;name=\"file\";filename=\"{0}\"\r\nContent-Type:application/octet-stream\r\n\r\n", fileName));
  247. byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString());
  248. request.ContentLength = itemBoundaryBytes.Length + postHeaderBytes.Length + fs.Length + endBoundaryBytes.Length;
  249. using (Stream postStream = request.GetRequestStream())
  250. {
  251. postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
  252. postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
  253. int bytesRead = 0;
  254. int arrayLeng = fs.Length <= 4096 ? (int)fs.Length : 4096;
  255. byte[] bArr = new byte[arrayLeng];
  256. int counter = 0;
  257. fs.Position = 0;
  258. while ((bytesRead = fs.Read(bArr, 0, arrayLeng)) != 0)
  259. {
  260. counter++;
  261. postStream.Write(bArr, 0, bytesRead);
  262. }
  263. postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
  264. }
  265. //发送请求并获取相应回应数据
  266. using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
  267. {
  268. //直到request.GetResponse()程序才开始向目标网页发送Post请求
  269. using (Stream instream = response.GetResponseStream())
  270. {
  271. StreamReader sr = new StreamReader(instream, Encoding.UTF8);
  272. //返回结果网页(html)代码
  273. string content = sr.ReadToEnd();
  274. return content;
  275. }
  276. }
  277. }
  278. }
  279. #region public static 方法
  280. /// <summary>
  281. /// 将请求的流转化为字符串
  282. /// </summary>
  283. /// <param name="info"></param>
  284. /// <returns></returns>
  285. public static string GetStr(Stream info)
  286. {
  287. string result = "";
  288. try
  289. {
  290. using (StreamReader sr = new StreamReader(info, System.Text.Encoding.UTF8))
  291. {
  292. result = sr.ReadToEnd();
  293. sr.Close();
  294. }
  295. }
  296. catch
  297. {
  298. }
  299. return result;
  300. }
  301. /// <summary>
  302. /// 参数转码
  303. /// </summary>
  304. /// <param name="str"></param>
  305. /// <returns></returns>
  306. public static string stringDecode(string str)
  307. {
  308. return HttpUtility.UrlDecode(HttpUtility.UrlDecode(str, System.Text.Encoding.GetEncoding("UTF-8")), System.Text.Encoding.GetEncoding("UTF-8"));
  309. }
  310. /// <summary>
  311. /// json反序列化
  312. /// </summary>
  313. /// <typeparam name="T"></typeparam>
  314. /// <param name="json"></param>
  315. /// <returns></returns>
  316. public static T Deserialize<T>(string json)
  317. {
  318. try
  319. {
  320. T obj = Activator.CreateInstance<T>();
  321. using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json)))
  322. {
  323. DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
  324. return (T)serializer.ReadObject(ms);
  325. }
  326. }
  327. catch
  328. {
  329. return default(T);
  330. }
  331. }
  332. #endregion
  333. public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  334. { // 总是接受
  335. return true;
  336. }
  337. }
  338. public enum HttpRequestType
  339. {
  340. POST,
  341. GET,
  342. DELETE,
  343. PUT,
  344. PATCH,
  345. HEAD,
  346. TRACE,
  347. OPTIONS
  348. }
复制代码

然后列出HttpHelper的调用

1、不带参数调用

  1. public bool ConnectServer()
  2. {
  3. try
  4. {
  5. string url = "https://i.cnblogs.com";
  6. string xml = HttpHelper.SendRequest(url, HttpRequestType.POST, null, null, Encoding.UTF8, Encoding.UTF8);
  7. NormalResponse nr = HuaweiXMLHelper.GetNormalResponse(xml);
  8. if (nr.Code == "0")
  9. {
  10. HttpHelper.SetHttpCookie(HttpHelper.GetLastCookie());
  11. mIsConnect = true;
  12. return true;
  13. }
  14. else
  15. {
  16. mIsConnect = false;
  17. return false;
  18. }
  19. }
  20. catch (System.Exception ex)
  21. {
  22. mIsConnect = false;
  23. return false;
  24. }
  25. }
复制代码

2.带参数调用

  1. private bool HandleIntelligentTask(string taskId,bool bStop)
  2. {
  3. try
  4. {
  5. if (!mIsConnect)
  6. {
  7. return false;
  8. }
  9. StringBuilder sb = new StringBuilder();
  10. sb.AppendFormat("<request>\r\n");
  11. sb.AppendFormat("<task_id>{0}</task_id>\r\n", taskId);//<!-- task-id为调用方生成的UUID或其它串 -->
  12. sb.AppendFormat("<status>{0}</status>\r\n",bStop?0:1);
  13. sb.AppendFormat("</request>\r\n");
  14. string xml = sb.ToString();
  15. string url = mIAServerUrl + "/sdk_service/rest/video-analysis/handle-intelligent-analysis";
  16. string xml2 = HttpHelper.SendRequest(url, HttpRequestType.POST, "text/plain;charset=utf-8", xml, Encoding.UTF8, Encoding.UTF8);
  17. NormalResponse nr = HuaweiXMLHelper.GetNormalResponse(xml2);
  18. if (nr.Code == "0")
  19. {
  20. return true;
  21. }
  22. else
  23. {
  24. return false;
  25. }
  26. }
  27. catch (System.Exception ex)
  28. {
  29. return false;
  30. }
  31. }
复制代码

3.异步调用

  1. private void ReStartAlarmServer(List<string> list, string alarmUrl, Thread[] listThread)
  2. {
  3. StopAlarm(alarmUrl, listThread);
  4. listThread[0]= new Thread(new ThreadStart(delegate()
  5. {
  6. try
  7. {
  8. if (!mIsConnect)
  9. {
  10. mLog.Error("未登录!--ReStartAlarmServer-结束!");
  11. return;
  12. }
  13. mLog.Info("ReStartAlarmServer开始报警连接....");
  14. if (String.IsNullOrWhiteSpace(alarmUrl)) return;
  15. mLog.InfoFormat("ReStartAlarmServer请求报警:URL={0}", alarmUrl);
  16. string xml = "task-id=0";
  17. string xml2 = HttpHelper.SendRequest(alarmUrl, HttpRequestType.POST, "application/x-www-form-urlencoded", xml, Encoding.UTF8, Encoding.UTF8, AlarmCallBack);
  18. mLog.Info("ReStartAlarmServer报警连接成功!");
  19. }
  20. catch (System.Threading.ThreadAbortException ex)
  21. {
  22. mLog.Info("ReStartAlarmServer线程已人为终止!" + ex.Message, ex);
  23. }
  24. catch (System.Exception ex)
  25. {
  26. mLog.Error("ReStartAlarmServer开始报警连接失败:" + ex.Message, ex);
  27. mLog.Info("ReStartAlarmServer开始重新报警连接....");
  28. mTimes = 50;
  29. }
  30. finally
  31. {
  32. }
  33. }));
  34. listThread[0].IsBackground = true;
  35. listThread[0].Start();
  36. }
  37. private void AlarmCallBack(IAsyncResult ir)
  38. {
  39. try
  40. {
  41. HttpWebRequest webRequest = (HttpWebRequest)ir.AsyncState;
  42. string salarmUrl = webRequest.Address.OriginalString;
  43. Thread[] alarmThead = dicAlarmUrls[salarmUrl];
  44. HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(ir);
  45. Stream stream = response.GetResponseStream();
  46. alarmThead[1]= new Thread(new ThreadStart(delegate()
  47. {
  48. try
  49. {
  50. byte[] buffer = new byte[mAlarmReadCount];
  51. int count = 0;
  52. string strMsg = "";
  53. int startIndex = -1;
  54. int endIndex = -1;
  55. NormalResponse res = null;
  56. DateTime dtStart = DateTime.Now;
  57. DateTime dtEnd = DateTime.Now;
  58. while (!mIsCloseAlarm)
  59. {
  60. count = stream.Read(buffer, 0, mAlarmReadCount);
  61. if (count > 0)
  62. {
  63. strMsg += Encoding.UTF8.GetString(buffer, 0, count);
  64. startIndex = strMsg.IndexOf("<response>");
  65. endIndex = strMsg.IndexOf("</response>");
  66. string xml = strMsg.Substring(startIndex, endIndex - startIndex + "</response>".Length);
  67. res = HuaweiXMLHelper.GetNormalResponse(xml);
  68. strMsg = strMsg.Substring(endIndex + "</response>".Length);
  69. startIndex = -1;
  70. endIndex = -1;
  71. break;
  72. }
  73. dtEnd = DateTime.Now;
  74. if ((dtEnd - dtStart).TotalSeconds > 10)
  75. {
  76. throw new Exception("连接信息未有获取到,需要重启报警!");
  77. }
  78. }
  79. while (!mIsCloseAlarm)
  80. {
  81. count = stream.Read(buffer, 0, mAlarmReadCount);
  82. if (count > 0)
  83. {
  84. string temp = Encoding.UTF8.GetString(buffer, 0, count);
  85. strMsg += temp;
  86. while (strMsg.Length > 0)
  87. {
  88. if (startIndex == -1)//未发现第一个<task-info>
  89. {
  90. startIndex = strMsg.IndexOf("<task-info>");
  91. if (startIndex == -1)
  92. {
  93. if (strMsg.Length >= "<task-info>".Length)
  94. {
  95. strMsg = strMsg.Substring(strMsg.Length - "<task-info>".Length);
  96. }
  97. break;
  98. }
  99. }
  100. if (startIndex >= 0)
  101. {
  102. int i = startIndex + "<task-info>".Length;
  103. int taskInfoEndIndex = strMsg.IndexOf("</task-info>", i);
  104. if (taskInfoEndIndex > 0)//必须有任务结束节点
  105. {
  106. i = taskInfoEndIndex + "</task-info>".Length;
  107. int i1 = strMsg.IndexOf("</attach-rules>", i);//找到轨迹节点结束
  108. int i2 = strMsg.IndexOf("</alarm>", i);//找到报警节点结束,发现一条报警
  109. if (i1 == -1 && i2 == -1)//没有标志结束
  110. {
  111. break;
  112. }
  113. else if (i1 >= 0 && (i1 < i2 || i2 == -1))//找到轨迹结束节点
  114. {
  115. strMsg = strMsg.Substring(i1 + "</attach-rules>".Length);
  116. startIndex = -1;
  117. endIndex = -1;
  118. continue;
  119. }
  120. else if (i2 > 0 && (i2 < i1 || i1 == -1))//找报警节点
  121. {
  122. endIndex = i2;//找到报警节点结束,发现一条报警
  123. string alarmXml = "<taskalarm>" + strMsg.Substring(startIndex, endIndex - startIndex + "</alarm>".Length) + "</taskalarm>";
  124. Thread th = new Thread(new ThreadStart(delegate()
  125. {
  126. ParseAlarmXml(alarmXml);
  127. }));
  128. th.IsBackground = true;
  129. th.Start();
  130. strMsg = strMsg.Substring(endIndex + "</alarm>".Length);
  131. startIndex = -1;
  132. endIndex = -1;
  133. continue;
  134. }
  135. }
  136. else
  137. {
  138. break;
  139. }
  140. }
  141. }
  142. }
  143. else
  144. {
  145. Console.WriteLine("##########读取报警反馈:无");
  146. Thread.Sleep(1000);
  147. }
  148. }
  149. }
  150. catch (System.Threading.ThreadAbortException ex)
  151. {
  152. mLog.Info("AlarmCallBack...7");
  153. try
  154. {
  155. if (stream != null)
  156. {
  157. stream.Close();
  158. stream.Dispose();
  159. response.Close();
  160. }
  161. }
  162. catch
  163. {
  164. }
  165. mLog.Info("AlarmCallBack线程已人为终止!--0" + ex.Message, ex);
  166. }
  167. catch(IOException ex)
  168. {
  169. mLog.Info("AlarmCallBack...8");
  170. try
  171. {
  172. if (stream != null)
  173. {
  174. stream.Close();
  175. stream.Dispose();
  176. response.Close();
  177. }
  178. }
  179. catch
  180. {
  181. }
  182. }
  183. catch (ObjectDisposedException ex)
  184. {
  185. mLog.Info("AlarmCallBack...9");
  186. mLog.Info("AlarmCallBack读取流已人为终止!--2" + ex.Message, ex);
  187. try
  188. {
  189. if (stream != null)
  190. {
  191. stream.Close();
  192. stream.Dispose();
  193. response.Close();
  194. }
  195. }
  196. catch
  197. {
  198. }
  199. }
  200. catch (System.Exception ex)
  201. {
  202. mLog.Info("AlarmCallBack...10");
  203. mLog.Error("AlarmCallBack 0:" + ex.Message,ex);
  204. try
  205. {
  206. if (stream != null)
  207. {
  208. stream.Close();
  209. stream.Dispose();
  210. response.Close();
  211. }
  212. }
  213. catch
  214. {
  215. }
  216. }
  217. finally
  218. {
  219. }
  220. }));
  221. alarmThead[1].IsBackground = true;
  222. alarmThead[1].Start();
  223. }
  224. catch (System.Exception ex)
  225. {
  226. mLog.Info("AlarmCallBack...11");
  227. mLog.Error("AlarmCallBack 1:" + ex.Message,ex);
  228. mLog.Info("AlarmCallBack开始重新报警连接....3");
  229. mTimes = 50;
  230. }
  231. finally
  232. {
  233. }
  234. }
复制代码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持程序员之家。

您可能感兴趣的文章:

  • C#调用C++版本dll时的类型转换需要注意的问题小结
  • C#调用Java类的实现方法
  • C#使用Process类调用外部程序分解
  • PHP调用C#开发的dll类库方法
  • C#中子类调用父类的实现方法
  • SQL Server中调用C#类中的方法实例(使用.NET程序集)
  • C#调用mmpeg进行各种视频转换的类实例
  • C#中派生类调用基类构造函数用法分析
  • C#使用Process类调用外部exe程序
  • C#中调用VB中Inputbox类的实现方法


相关帖子

回复

使用道具 举报