2017-01-30 17 views
0

При отладочном режиме \ релиз ошибки Скрипач трассировки:Почему код ведет себя по-другому в C# Interactive (Roslyn) и в режиме debug release?

[Fiddler] The connection to 'host.com' failed. <br/>System.Security.SecurityException Failed to negotiate HTTPS connection with server.fiddler.network.https&gt; HTTPS handshake to host.com (for #76) failed. System.IO.IOException Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. &lt; An existing connection was forcibly closed by the remote host 

Оригинальный вопрос: я получил кусок кода:

HttpTransportOverWebClient c = new HttpTransportOverWebClient(); 
c.GetURL("https://web.page/query") 

Где GetURL некоторая обертка:

public bool GetURL(string URL) 
     { 
      try 
      { 
       web.Headers.Add("User-Agent", browserAgent); 
       byte[] data = web.DownloadData(URL); 
       string characterSet = web.Response.CharacterSet; 
       string encoding = (characterSet == null || characterSet == "" || characterSet.ToUpper() == "NONE") ? "UTF-8" : web.Response.CharacterSet.ToUpper(); 
       html = Encoding.GetEncoding(encoding).GetString(data); 
       return true; 
      } 
      catch (Exception ex) 
      { 
       lastException = web.LastException == null ? new WebException(ex.Message) : web.LastException; 
      } 
      return false; 
     } 

Поведение в C# Интерактивный режим:

GetURL return true and html contains data

Поведение в режиме \ релиз отладки:

GetURL return false and ex contains error below:

An exception occurred during a WebClient request. 
    at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) 
    at System.Net.WebClient.DownloadData(Uri address) 
    at HttpCrawler.HttpTransportOverWebClient.GetURL(String URL) in ..HttpTransportOverWebClient.cs:line xx 

Внутреннее исключение:

at System.Net.WebClient.DownloadBitsState.SetResponse(WebResponse response) 
    at System.Net.WebClient.DownloadBits(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp) 
    at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) 

Отвод совет

ответ

1

Решение

Я предполагаю, что C# интерактивна предварительно настроена каким-то образом, что она способна по умолчанию ServicePointManager.SecurityProtocol к более старой версии. В качестве резолюции я добавляю код:

using System.Net; 
.... 
ServicePointManager.SecurityProtocol = 
     SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; 

 Смежные вопросы

  • Нет связанных вопросов^_^