Small Basic Known Issue: 53795 - Network Objects Don't Work for TLS Host
Overview
Network objects such like Network.DownloadFile or ImageList.LoadImage don't work with some host such like Microsoft Tech Community or Flickr.
Phenomenon
Following operations return nothing with the host which may have the security protocol type TLS12.
- Network.DownloadFile
- Network.GetWebPageContents
- ImageList.LoadImage
- Shapes.AddImage
- GraphicsWindow.DrawImage
Following code is a sample to reproduce this issue. This sample is from Small Basic Getting Started Guide: Appendix A. This program should show a picture from Flickr when mouse click.
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.MouseDown = OnMouseDown
Sub OnMouseDown
pic = Flickr.GetRandomPicture("mountains, river")
GraphicsWindow.DrawResizedImage(pic, 0, 0, 640, 480)
EndSub
But nothing happens.
Workaround
LDNetwork.DownloadFile in LitDev Extension can download the same files.
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.MouseDown = OnMouseDown
Sub OnMouseDown
pic = Flickr.GetRandomPicture("mountains, river")
path = File.GetTemporaryFilePath()
size = LDNetwork.DownloadFile(path, pic)
GraphicsWindow.DrawResizedImage(path, 0, 0, 640, 480)
EndSub
Possible Cause
This issue may because of new security protocol TLS. Following PowerShell function work well with such hosts above.
function Get-WebPageContents($url) {
# Simulates Small Basic NetWork.GetWebPageContents()
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$wc = New-Object System.Net.WebClient
$st = $wc.OpenRead($url)
$enc = [System.Text.Encoding]::GetEncoding('UTF-8')
$sr = New-Object System.IO.StreamReader($st, $enc)
$html = $sr.ReadToEnd()
$sr.Close()
$html
}
See Also
- [[articles: Microsoft Small Basic v1.2: Known Issues]]