110,534
社区成员
发帖
与我相关
我的任务
分享
private void timer2_Tick(object sender, EventArgs e)
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(frmIP.WoshouIP);
myReq.Method = "GET";//设置请求的方法
myReq.Timeout = 5000;
myReq.ServicePoint.ConnectionLimit = 20;
HttpWebResponse myRes = null;
try
{
myRes = (HttpWebResponse)myReq.GetResponse();
using (StreamReader sr = new StreamReader(myRes.GetResponseStream()))
{
string strgetok = sr.ReadToEnd();
if (strgetok != "OK")
{
txtThrowRong.AppendText(DateTime.Now.ToString() + " 与远程网络交互握手失败,未得到反馈,请确认网络连接良好\r\n");
txtThrowRong.ScrollToCaret();
string strErrors = DateTime.Now.ToString() + "\r\n" + "与远程网络交互握手失败,未得到反馈,未得到返回信息\r\n\r\n";
File.AppendAllText("Errors.LOG", strErrors);
SendErrorsLog(strErrors);
}
}
}
catch (Exception ex)
{
txtThrowRong.AppendText(DateTime.Now.ToString() + " 与远程网络交互握手失败,请确认网络连接良好\r\n");
txtThrowRong.ScrollToCaret();
string strErrors = DateTime.Now.ToString() +" 与远程网络交互握手失败\r\n" + "错误报告:" + ex.ToString() + "\r\n\r\n";
File.AppendAllText("Errors.LOG", strErrors);
SendErrorsLog(strErrors);
}
finally
{
if (myReq != null) { myReq.Abort(); }//销毁HttpWebRequest
if (myRes != null) { myRes.Close(); myRes = null; }
}
}