htmlSendSync(conID As String, method As String, url As String, timeout As Integer) As String

 

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.

 

Note: Be aware that calling SendSync can cause your app's UI to "freeze" while it waits for the result.

 

Use the example script below to test this function against our test webservice (https://test.nwscloud.ch/test)

 

 

Parameters:

 

Name

Type

Description

conID

String

Identifier of existing htmlConnection object

method

String

Name of a valid http request method, like:

GET, POST, PATCH, PUT, DELETE, etc.


For an introduction to http request methods refer to:
https://www.w3schools.com/tags/ref_httpmethods.asp

url

String

http or https address and path to webservice

timeout

Integer

time to wait for response of webservice, in seconds

 

Returns:

 

Type

Value

Description

String

The response of the webservice, a text in UTF8

encoding.

String

ERROR

An exception occurred while accessing the webservice.

The send request failed.

 

Available in:

 

WindowMain

WindowLink

YES

NO

 

 

Example XojoScript:

 

// Create new URLConnection

Dim conID As String = htmlConnection

 

// Set contents as JSON string

Var json As String = "{""id"":12345,""name"":""John Doe"",""email"":""jd@example.com""}"

 

// Set Request header contents (send data)

Var content As String = htmlRequestContent(conID,json,"application/json")

 

If content = "ERROR" Then

MsgBox("ERROR : Setting request content header failed.")

Call htmlConnectionClose(conID)

Return

End If

 

// Define path to test webservice

Dim url As String = "https://test.nwscloud.ch/test"

 

// Send Update Request for current address to Webserver

Dim jsonresponse As String = htmlsendSync(conID,"POST", url,15)

 

MsgBox("Response : " + jsonresponse)

 

Call htmlConnectionClose(conID)