URLConnection.SendSync

From Xojo Documentation

Method

URLConnection.SendSync(method As String, URL As String, timeout As Integer) As String

Supported for all project types and targets.

Synchronously sends a request using an HTTP method such as GET or POST. Results are returned as a String. Send can be used to send both standard "http" and secure "https" requests. The timeout is in seconds.


Method

URLConnection.SendSync(method As String, URL As String, file As FolderItem, timeout As Integer)

Supported for all project types and targets.

Synchronously sends a request using an HTTP method such as GET or POST and returns the output in file. The results are saved to the supplied file. Send can be used to send both standard "http" and secure "https" requests. The timeout is in seconds.

Notes

Be aware that calling SendSync can cause your app's UI to "freeze" while it waits for the result. For normal processing you may want to use the asynchronous Send method instead, which calls the ContentReceived or FileReceived events when data is received.

This method raises a RuntimeException if an App Transport Security error occurs on macOS due to using a non-secure URL without the appropriate entry in the plist.

Sample Code

Var content As String
content = MyConnection.SendSync("GET", "http://127.0.0.1:8080/GetData", 30)

Sends a GET request, saving the response to a file:

Var outputFile As FolderItem = SpecialFolder.Documents.Child("data.json")
MyConnection.SendSync("GET", "http://127.0.0.1:8080/GetData", outputFile, 30)

To make a secure request, use "https" in the URL:

Var outputFile As FolderItem = SpecialFolder.Documents.Child("data.json")
MyConnection.SendSync("GET", "https://www.mydomain.com/GetData", outputFile, 30)

See Also