HTTPSocket.Post

From Xojo Documentation

Method

HTTPSocket.Post(URL as String)

Supported for all project types and targets.

Asynchronously sends a POST command to the URL. When the page content is received, the HTTPSocket.PageReceived event handler is called with the response available in the content parameter.


Method

HTTPSocket.Post(URL as String, File As FolderItem)

Supported for all project types and targets.

Asynchronously sends a POST command to the URL. The response is downloaded directly to the FolderItem.

The HTTPSocket.DownloadComplete event handler is called when the response data has finished downloading.

You need to subclass HTTPSocket (or use AddHandler) so that you can handle the appropriate events.


Method

HTTPSocket.Post(URL as String, TimeOut as Integer) As String

Supported for all project types and targets.

Synchronously issues a POST command to the URL and returns a String that contains the response. TimeOut is the number of seconds to wait for the result.

If Timeout is set to zero, then there is no timeout period and the socket waits until it receives the page or gets an error.

HTTPSocket.ErrorCode is -1 if the Timeout value is reached.


Method

HTTPSocket.Post(URL as String, File As FolderItem, TimeOut as Integer) As Boolean

Supported for all project types and targets.

Synchronously issues a POST command to the URL and downloads the response directly to the FolderItem. When the download has finished, True is returned if successful, False if there was an error. TimeOut is the number of seconds to wait for the result.

HTTPSocket.ErrorCode is -1 if the Timeout value is reached.

Notes

For the synchronous versions of this method, set the HTTPSocket.Yield property to True to allow for background activities while waiting.

Examples

This example does a synchronous POST to a service that returns what you POSTed to it as JSON:

Var d As New Dictionary

d.Value("Test") = "TestValue"
d.Value("Value2") = "Testing"

Socket.SetFormData(d)

// This service simply returns the post data as the result
Var result As String
result = Socket.Post("http://httpbin.org/post", 30) // Synchronous

result = DefineEncoding(result, Encodings.UTF8)

MessageBox(result)


To do this asynchronous, call Post without a timeout:

Var d As New Dictionary

d.Value("Test") = "TestValue"
d.Value("Value2") = "Testing"

Socket.SetFormData(d)

// This service simply returns the post data as the result
Socket.Post("http://httpbin.org/post")

The results will be available in the PageReceived event handler in the content parameter.

Sub PageReceived(url As String, httpStatus As Integer, headers As InternetHeaders, content As String)
Var data As String
data = DefineEncoding(content, Encodings.UTF8)

ResultArea.Value = data
End Sub