Сообщение об ошибке : запрос был прерван: не удалось создать безопасный канал SSL/TLS.
Я использую следующий код в C#, чтобы прочитать веб-сайт SSL, на который приходит ошибка Error.txt -
Exception Read: The request was aborted: Could not create SSL/TLS secure channel.:
//On the top of the page using System.Net; using System.IO; //My methods private void btnGetData_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); try { // used on each read operation byte[] buf = new byte[8192]; ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); Uri uri = new Uri("https://www.zillow.com/homedetails/2138325511_zpid"); WebRequest webRequest = WebRequest.Create(uri); WebResponse webResponse = webRequest.GetResponse(); //ReadFrom(webResponse.GetResponseStream()); Stream response = webResponse.GetResponseStream(); string tempString = null; int count = 0; do { // fill the buffer with data count = response.Read(buf, 0, buf.Length); // make sure we read some data if (count != 0) { // translate from bytes to ASCII text tempString = Encoding.ASCII.GetString(buf, 0, count); // continue building the string sb.Append(tempString); } } while (count > 0); // any more data to read? } catch (Exception ex2) { try { StreamWriter sw = new StreamWriter(Environment.CurrentDirectory + "\\Error.txt"); //Write a line of text sw.WriteLine("Exception Read: " + ex2.Message); //Close the file sw.Close(); this.Close(); return; } catch(Exception exinner2) { Console.WriteLine("Exception Read: " + exinner2.Message); this.Close(); return; } } // write to text file page source try { //Pass the filepath and filename to the StreamWriter Constructor StreamWriter sw = new StreamWriter(Environment.CurrentDirectory + "\\Pageoutput.txt"); //Write a line of text sw.WriteLine(sb.ToString()); //Close the file sw.Close(); MessageBox.Show("Data inserted Successfully"); } catch (Exception ex) { try { StreamWriter sw = new StreamWriter(Environment.CurrentDirectory + "\\Error.txt"); //Write a line of text sw.WriteLine("Exception Write: " + ex.Message); //Close the file sw.Close(); } catch (Exception exinner) { Console.WriteLine("Exception Write: " + exinner.Message); } } } public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; }
Что я уже пробовал:
Я пробовал методом проб и ошибок из многих статей в интернете, но безрезультатно.