2016-03-20 21 views
2

Bu resmi istemeye çalışıyorum: https://www.kamerstunt.nl/file/img/web/woning/9577323WenumWieselZwolseweg-142d_6.jpg Bunu okuduğunuzda resim artık mevcut değilse kaldırılmış, ancak yine de söz konusu SSL sertifikasını görüntüleyebileceksiniz. Tarayıcımı kullanarak sayfaya başarılı bir şekilde ulaşabildim, görüntüyü istedim ve geçerli bir SSL sertifikası görebildim.ASP.NET "İstek iptal edildi: SSL/TLS güvenli kanal oluşturulamadı" da yapılandırılmış servicepointmanager ile birlikte oluşur

Burada kontrol:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12 

Ama sonra hataları olsun:

Dim imgRequest As WebRequest = WebRequest.Create("https://www.kamerstunt.nl/file/img/web/woning/9577323WenumWieselZwolseweg-142d_6.jpg") 
Dim imgResponse As WebResponse 
ServicePointManager.Expect100Continue = True 
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls 
'//I also tried: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Ssl3 
imgResponse = imgRequest.GetResponse() 
Dim streamPhoto As Stream = imgResponse.GetResponseStream() 

Denedim: 'Tls12' is not a member of 'System.Net.SecurityProtocolType' ve 'Tls11' is not a member of 'System.Net.SecurityProtocolType'

The request was aborted: Could not create SSL/TLS secure channel Yani benim kod çözüm belirtti

Ben de pencere 512 bit ile DHE engellemeyecek izin kayıt değiştirmeye çalışmış ve HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\KeyExchangeAlgorithms\Diffie-Hellman.

altında 0x00000200 (512) değeriyle ClientMinKeyBitLength eklendi Ama yine de ... neden başarısız?

+0

dosyayı indirmek isteyen var mı? – Codexer

+0

Bir memorystream'e yüklemeye çalışıyorum (bu yüzden diske değil): 'Dim akışıFazla Akış olarak = imgResponse.GetResponseStream()' – Flo

+0

Lütfen güncellenmiş yanıtlara bakın ... denenmiş ve test edilmiştir. – Codexer

cevap

1

Kullandığım bir çözüm Stream döndürür ... Ayrıca bir bayt dizisi döndürdüğü ve ardından bu bayt dizisinden yeni bir MemoryStream oluşturacak şekilde de değiştirebilirsiniz. Ayrıca geçmek için bir dize türü yerine, bir URL'ye değiştirebilirsiniz, ama bu size kalmış.

Public Function GetRemoteStream(uRL As String) As MemoryStream 
    Dim webClient As New WebClient() 
    Dim imageBytes As Byte() = webClient.DownloadData(uRL) 
    Dim mem As New MemoryStream(imageBytes) 
    Return mem 
End Function 

Örnek Kullanım

Dim nStream As New MemoryStream 
nStream = GetRemoteStream(yoururlhere) 

DÜZENLEME OKUYUN *************************** *****************

Bunu inceledikten ve biraz daha kazdıktan sonra bir çözüm buldum. Görünen o ki, site SSL & Tls11 desteğini bıraktı.

4.5 çerçevesini hedefleyen yeni bir proje başlattım. Sonra kullanılan bu SecurityProtocolType ...

SecurityProtocolType.Tls12 

Çözüm

Değişim hedef çerçevesi için: 4.5 ve kullanım: SecurityProtocolType.Tls12. Şimdi protokol başka notta

Ben sarma tavsiye üzerine ... böyle

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 

görünmelidir senin Stream yüzden en düzgün bertaraf olsun. Örneğin:

Using stream As Stream = imgResponse.GetResponseStream() 
      Using ms As New MemoryStream() 
       Dim count As Integer = 0 
       Do 
        Dim buf As Byte() = New Byte(1023) {} 
        count = stream.Read(buf, 0, 1024) 
        ms.Write(buf, 0, count) 
       Loop While stream.CanRead AndAlso count > 0 
       'ms is your memory stream... as I take it you want the photo :) 
      End Using 
     End Using 

Çıktılarımın bir kanıtı ...öyle

enter image description here

+0

Kod resminizde 'Dim imageBytes As Byte() = webClient.DownloadData (uRL)' Hatayı alıyorum 'İstek iptal edildi: SSL/TLS güvenli kanal oluşturulamadı. ' – Flo

+0

Servicepointmanager'ınızda bunu deneyebilir misiniz? ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Veya SecurityProtocolType.Tls Veya SecurityProtocolType.Tls11 Veya SecurityProtocolType.Tls12' – Codexer

+0

Bunu kullanarak 2 hata alıyorum: '' Tls11 '' SecurityProtocolType '' üyesi değil ve '' Tls12 'değil 'SecurityProtocolType' adlı bir üye. Daha önce denediğim diğer kişiler (orijinal gönderiimde kod yorumuna bakın). Başka ne olabilir ki? – Flo

İlgili konular