2016-04-17 11 views
1

を使用して、いくつかのhttpsのホーム・ページをダウンロードすることはできません私は、C#を使用して、さまざまな小売サイトから、ホームページの単なるHTMLをいくつかのサイト情報をダウンロードしようとしています。 は、私は他の人のために、私は次の例外を取得しながら、がhttps、いくつかの作業の罰金がは、HttpWebRequestの

The underlying connection was closed: An unexpected error occurred on a send. 

内部例外は、私はそれが何かを持っていると思う

The handshake failed due to an unexpected packet format. 

を持って使用していくつかのサイトに問題があります私の人生のためにTLSと私はそれを把握することはできません。私はStack OverflowとHttpWebRequestのドキュメンテーションを全面的に行ってきました。

は、ここで私はサイトを呼び出すために使用して以下のサンプルコードだし、私は誰もがこの上の任意の洞察力を持っていたならば、それは狂気私を運転だ感謝されると思います。

public HttpWebResponse GetWebResponse(HtmlVerb verb, Uri uri) 
{ 

    var request = System.Net.WebRequest.CreateHttp(uri); 
    request.Method = verb.ToString(); 
    request.ProtocolVersion = HttpVersion.Version11; 
    request.CookieContainer = new CookieContainer(); 
    request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; 
    request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0"; 
    request.Timeout = (int)TimeSpan.FromSeconds(10).TotalMilliseconds; 
    request.AllowAutoRedirect = true; 
    request.ServerCertificateValidationCallback = delegate { return true; }; 
    request.Headers.Add("Accept-Language", "en-US,en;q=0.5"); 
    request.Headers.Add("Accept-Encoding", "gzip, deflate"); 
    request.ContentType = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; 
    request.KeepAlive = false; 

    return request.GetResponse() as HttpWebResponse; 
} 

種類よろしく

+0

はあなたにここで、URIでポートを指定しました:http://stackoverflow.com/questions/16895484/getting-handshake-failed-unexpected-packet-format-when-using-webclient-uploa? –

+0

https://blogs.technet.microsoft.com/netmon/p/downloads/またはhttps://www.wireshark.org/ –

答えて

0

この問題が発生して他の誰のために、私は仕事に、次の解決策を発見しました。 アプリケーション・コンテキストを初期化するために、アプリケーションの開始時に次のコード行、HTTPS を使用し、これらの問題のサイト今が含まれている場合は、正しくダウンロードします。

private const string DisableCachingName = @"TestSwitch.LocalAppContext.DisableCaching"; 
private const string DontEnableSchUseStrongCryptoName = @"Switch.System.Net.DontEnableSchUseStrongCrypto"; 
static void Main(string[] args) 
{ 
    AppContext.SetSwitch(DisableCachingName, true); 
    AppContext.SetSwitch(DontEnableSchUseStrongCryptoName, false); 
+0

を使用して実際に何が起こったかを診断してください – Fourat