For the current prerelease version 20.2pr3 we added NSURLSessionMBS and related classes to the MBS Xojo Plugins. Main reason is that we urgently needed a solution for a client to support HTTP/2 connections for a project. Long term plan is to add HTTP/2 to our CURL plugin someday, but for now it is easier to just leverage Apple's excellent NSURL Frameworks which do the heavy work for almost all network traffic in MacOS & iOS. The classes allow you to use the latest encryption settings automatically.
When using the classes, please first create an object of NSURLSessionConfigurationMBS class. Configure it to the options you need, e.g. what caching or cookie policies you like or whether to allow cellular or expensive connections.
Next you can initialize a new NSURLSessionMBS, usually via constructor and your own subclass to fill in the events. Alternatively for simple transfers you can use the sharedSession and use the default settings.
Then you use one of the NSURLSessionTaskMBS subclasses:
- NSURLSessionDataTaskMBS to run a normal HTTP request with result in memory.
- NSURLSessionUploadTaskMBS to do a HTTP upload with POST or PUT.
- NSURLSessionDownloadTaskMBS to download a bigger file to disk. This includes support for pausing and resuming downloads.
- NSURLSessionStreamTaskMBS allows you to skip the HTTP protocol and do your own streaming of whatever data you have.
- NSURLSessionWebSocketTaskMBS new in MacOS 10.15 allows to connect via web socket connection and allow you to send messages.
We formally deprecate NSURLConnectionMBS class, which is the older set of classes Apple provides for HTTP connections. You should move to NSURLSessionMBS soon. We won't remove them until Apple removes them, but you never know whether they will be part of next OS version.