Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSURLConnectionMBS class.

NSURLConnectionMBS.canHandleRequest(request as NSURLRequestMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Networking MBS MacBase Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns whether a request can be handled based on a preflight evaluation.

request: The request to evaluate.

Returns true if a preflight operation determines that a connection with request can be created and the associated I/O can be started, false otherwise.

The result of this method is valid as long as no NSURLProtocol classes are registered or unregistered, and request remains unchanged. Applications should be prepared to handle failures even if they have performed request preflighting by calling this method.

NSURLConnectionMBS.sendSynchronousRequest(request as NSURLRequestMBS, byref response as NSURLResponseMBS, byref error as NSErrorMBS) as Memoryblock

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa Networking MBS MacBase Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Performs a synchronous load of the specified URL request.
Example
dim request as new NSURLRequestMBS("http://www.monkeybreadsoftware.de/images/MBSLogo.jpg")
dim error as NSErrorMBS
dim response as NSURLResponseMBS
dim d as MemoryBlock = NSURLConnectionMBS.sendSynchronousRequest(request, response, error)

if d<>Nil then
dim pic as Picture = JPEGStringToPictureMBS(d, true)
window1.Backdrop = pic
end if

if error<>Nil then
MsgBox "Error: "+error.description
end if

request: The URL request to load. The request object is deep-copied as part of the initialization process. Changes made to request after this method returns do not affect the request that is used for the loading process.
response: Out parameter for the URL response returned by the server.
error: Out parameter used if an error occurs while processing the request.

Returns the downloaded data for the URL request. Returns nil if a connection could not be created or if the download fails.

A synchronous load is built on top of the asynchronous loading code made available by the class. The calling thread is blocked while the asynchronous loading system performs the URL load on a thread spawned specifically for this load request. No special threading or run loop configuration is necessary in the calling thread in order to perform a synchronous load.

Important: Because this call can potentially take several minutes to fail (particularly when using a cellular network in iOS), you should never call this function from the main thread of a GUI application.

If authentication is required in order to download the request, the required credentials must be specified as part of the URL. If authentication fails, or credentials are missing, the connection will attempt to continue without credentials.

Some examples using this method:

The items on this page are in the following plugins: MBS MacBase Plugin.


The biggest plugin in space...