c#基础连接已关闭:发送时发生意外错误

时间:2017-05-23 21:00:07

标签: c#

首先,我认为我的问题与stackoverflow中的其他主题完全不同,因为我已经尝试过其中的解决方案。

我正在使用.NET 4.5:

        HttpWebRequest MainRequest = (HttpWebRequest)WebRequest.Create(url);


        WebHeaderCollection myWebHeaderCollection = MainRequest.Headers;
        MainRequest.Method = "GET";

        MainRequest.Host = "aro.example.com";
        MainRequest.Timeout = 20000;
        MainRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
        myWebHeaderCollection.Add("Upgrade-Insecure-Requests", "1");
        MainRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36";
        myWebHeaderCollection.Add("Accept-Encoding", "gzip, deflate, sdch");
        myWebHeaderCollection.Add("Accept-Language", "en-US,en;q=0.8");
        MainRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
        MainRequest.ServicePoint.Expect100Continue = false;
        MainRequest.CookieContainer = new CookieContainer();
        HttpWebResponse MainResponse = (HttpWebResponse)MainRequest.GetResponse();

这会抛出底层的异常......

我补充说: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

我现在没有异常,但在超时发生之前也没有响应。

0 个答案:

没有答案