我写了一个控制台应用程序来下载文件。
此应用程序在我的结束时工作正常,但在我的客户端结束时抛出Timeout WebException。
我尝试在客户端逐行调试此程序以找到该行 “using(var stream = myRequest.GetResponse())”需要很长时间,然后抛出超时异常。
我尝试了我在网上找到的所有解决方案,在我可以使用的所有地方使用语句,我中止了所有请求。但仍然无法解决这个问题
有关此问题的任何建议吗?
string loginData = "*******";
CookieContainer cookiecontainer = new CookieContainer();
Uri target=new Uri("https://www.ftwilliam.com");
cookiecontainer.Add(new Cookie("CoreM_State", "8~-1~-1~-1~-1~3~3~5~3~3~7~7~|~~|~~|~~|~||||||~|~~|~~|~~|~~|~~|~~|~~|~") { Domain = target.Host });
cookiecontainer.Add(new Cookie("CoreM_State_Content", "6~|~F83B1D2BFCF9CE7A~A063AA2FDE6FF059~28D0274B261787BD~|~0~1~2") { Domain = target.Host });
cookiecontainer.Add(new Cookie("CMAVID", "30011373332532185583597") { Domain = target.Host });
cookiecontainer.Add(new Cookie("cmTPSet", "Y") { Domain = target.Host });
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://www.ftwilliam.com/cgi-bin/Enter.cgi");
myRequest.CookieContainer = cookiecontainer;
myRequest.Method = "POST";
myRequest.KeepAlive = true;
myRequest.AllowAutoRedirect = false;
myRequest.Referer = "https://www.ftwilliam.com/cgi-bin/Enter.cgi";
myRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0";
myRequest.ContentType = "application/x-www-form-urlencoded";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] loginDataBytes = encoding.GetBytes(loginData);
myRequest.ContentLength = loginDataBytes.Length;
using(var stream = myRequest.GetRequestStream())
{
stream.Write(loginDataBytes, 0, loginDataBytes.Length);
}