HTTPSecureSocket

From Xojo Documentation

Class (inherits from SSLSocket)

Used to do secure transmissions via the HTTP 1.0 protocol using the SSL or TLS protocols.

Events
AuthenticationRequired Error ProxyAuthenticationRequired
Connected HeadersReceived ReceiveProgress
DownloadComplete PageReceived SendProgress


Properties
Address HTTPProxyAddress RemoteAddress fa-lock-32.png
BytesAvailable fa-lock-32.png HTTPProxyPort RequestHeaders
BytesLeftToSend fa-lock-32.png HTTPStatusCode SSLConnected fa-lock-32.png
CertificateFile Handle fa-lock-32.png SSLConnecting fa-lock-32.png
CertificatePassword IsConnected fa-lock-32.png SSLConnectionType
CertificateRejectionFile LocalAddress fa-lock-32.png SSLEnabled
DefaultPort NetworkInterface Yield
ErrorCode Port


Methods
ClearRequestHeaders Listen SendRequest
Close Lookahead SetFormData
Connect PageHeaders SetPostContent
Disconnect Poll SetRequestContent
EncodeFormData Post SetRequestHeader
Get Purge
GetHeaders ReadAll

Notes

fa-info-circle-32.png
If you need HTTP 1.1 support, use URLConnection instead.

Use the HTTPSecureSocket class to perform secure communications via the HTTP protocol. It is identical to the HTTPSocket class except that it is derived from the SSLSocket class instead of the TCPSocket class. This means that you can use the Secure property of SSLSocket to switch to HTTPS. When you set Secure to True, the default port changes from 80 to 443. It supports HTTP proxies while in secure mode.

If you use a constructor in a subclass of HTTPSecureSocket, you must call the Super class's constructor in your subclass's constructor. The subclass will not work unless this is done. You can use the Super keyword for this purpose.

App Transport Security

Starting with OS X 10.11 and 2018r4, your apps have to use secure "https" connections or you will get this error: "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection". You can work around this by providing a plist with your app to indicate what non-secure URLs you are using. For more information:

Xojo Cloud

Web apps running on Xojo Cloud first have to use the FirewallPort class to open the port used to connect to an outside web server.

Examples

A simple, secure connection:

Dim secureSite As New HTTPSecureSocket
secureSite.Secure = True
secureSite.ConnectionType = SSLSocket.TLSv12
Dim data As String
data = secureSite.Get("https://www.example.com", 30)

The following example posts a simple form:

Dim form As Dictionary
Dim socket1 As HTTPSecureSocket
socket1 = New HTTPSecureSocket
socket1.Secure = True

// create and populate the form object
form = New Dictionary
form.Value("firstname") = "Bob"
form.Value("lastname") = "Brown"

// setup the socket to POST the form
socket1.SetFormData(form)
socket1.Post("https://www.myformlocation.com/form.php")

See Also

URLConnection, HTTPSocket, SSLSocket, SocketCore, TCPSocket, Xojo.Net.HTTPSocket classes.