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?

Community
  • 1
  • 1
Adam
  • 6,041
  • 36
  • 120
  • 208

1 Answers1

1

Here is a solution I use that returns a Stream... You can also modify it so it returns a byte array and then create a new MemoryStream from that byte array. Also instead of a string type to pass you can change it to a url, but that's up to you.

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

Example Usage

 Dim nStream As New MemoryStream
 nStream = GetRemoteStream(yoururlhere)

EDIT PLEASE READ ********************************************

After looking into this and digging a little further, I found a solution. It seem's that the site has dropped support for SSL & Tls11.

I started a new project targeting 4.5 framework. I then used this SecurityProtocolType...

 SecurityProtocolType.Tls12

Solution

Change the target framework to: 4.5 and use: SecurityProtocolType.Tls12. Now your protocol should look like this...

 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

On another note

I recommend wrapping your Streamso it get's properly disposed of. For example:

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

Here's proof of my output...

enter image description here

Trevor
  • 7,777
  • 6
  • 31
  • 50
  • On your code line `Dim imageBytes As Byte() = webClient.DownloadData(uRL)` I get the error `The request was aborted: Could not create SSL/TLS secure channel.` – Adam Mar 21 '16 at 15:31
  • In your servicepointmanager can you try this? `ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12` – Trevor Mar 21 '16 at 15:40
  • Using that I get 2 errors: `'Tls11' is not a member of 'SecurityProtocolType'.` and `'Tls12' is not a member of 'SecurityProtocolType'.` The others I already tried (see code comment in my original post). What else could it be? – Adam Mar 21 '16 at 16:51
  • Thanks. I looked into changing the target framework, but am having issues with that...please see this post: http://stackoverflow.com/questions/36190394/asp-net-the-targetframework-attribute-is-not-allowed. How would I go about changing the targetframework for a website project? – Adam Mar 27 '16 at 04:22
  • Change it at project level..? `Right click on project --> Properties --> Application --> Target Framework` change that... – Trevor Mar 27 '16 at 04:24