2

I'm trying to request this image: https://www.kamerstunt.nl/file/img/web/woning/9577323WenumWieselZwolseweg-142d_6.jpg If the image no longer exists when you read this, it might have been removed, but you'd still be able to view the SSL certificate in question. Using my browser I was able to successfully navigate to the page, request the image and see a valid SSL certificate.

I checked here: The request was aborted: Could not create SSL/TLS secure channel

So I added that solution to my code:

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()

I tried:

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

But then I get errors: 'Tls12' is not a member of 'System.Net.SecurityProtocolType' and 'Tls11' is not a member of 'System.Net.SecurityProtocolType'

I also tried to change the registry to allow windows to not block DHE with 512 bits and added ClientMinKeyBitLength with 0x00000200(512) value under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\KeyExchangeAlgorithms\Diffie-Hellman.

But still it fails...why?

4

1 回答 1

1

这是我使用的一个解决方案,它返回一个Stream......您也可以修改它,使其返回一个字节数组,然后从该字节数组创建一个新的 MemoryStream 。此外,您可以将其更改为 url,而不是传递的字符串类型,但这取决于您。

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

示例用法

 Dim nStream As New MemoryStream
 nStream = GetRemoteStream(yoururlhere)

编辑请阅读********************************************

在研究了这个并进一步挖掘之后,我找到了一个解决方案。该网站似乎已放弃对 SSL 和 Tls11 的支持。

我开始了一个针对4.5 框架的新项目。然后我用这个SecurityProtocolType...

 SecurityProtocolType.Tls12

解决方案

将目标框架更改为:4.5并使用:SecurityProtocolType.Tls12。现在你的协议应该是这样的......

 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

另一个注意事项

我建议包装你的Stream,以便妥善处理。例如:

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

这是我的输出的证明......

在此处输入图像描述

于 2016-03-21T02:30:50.090 回答