HTTPSocket
From Xojo Documentation
This item was deprecated in version 2019r1. Please use URLConnection as a replacement. |
Used to send and receive data via the HTTP 1.0 protocol.
Events | |||||||||
|
Properties | |||||||||||||||
|
Notes
If you need HTTP 1.1 support, use URLConnection instead. |
Use the HTTPSocket class to send and receive data via the HTTP protocol. Since this is a subclass of the TCPSocket class, all the standard socket APIs are also available. To perform secure communications (via HTTPS), use the HTTPSecureSocket class instead. It is otherwise identical, except that it is subclassed from SSLSocket instead of TCPSocket. This makes all the options for encrypted communications available to HTTPSecureSocket objects.
If you use a constructor in a subclass of HTTPSocket, you must call the super class's constructor in your subclass's constructor. The subclass fail when you try to download.
When using the optional Timeout parameter of the Get or GetHeaders methods the page will be received or posted in a synchronous manner. That is, your app will wait until the page has been received or posted before it proceeds. If Timeout is set to zero, the socket will wait indefinitely or until it receives an error.
To use synchronous mode, pass the optional parameter. For example,
When using synchronous mode, you can set the Yield property to True to tell the socket to yield time to other events and code to execute while waiting. Simply insert a statement such as
to allow background processes to execute while waiting.
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.
Sample Code
The following example retrieves the specified URL synchronously:
For asynchronously transfers you need to subclass HTTPSocket, call get without timeout parameter and get result in HTTPSocket.PageReceived event.
The following example posts a simple form:
Dim socket1 As New HTTPSocket
// 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("http://www.myformlocation.com/form.php")
To send one or more cookies with an HTTP request:
See Also
URLConnection, HTTPSecureSocket, SocketCore, TCPSocket, Xojo.Net.HTTPSocket classes.