htmlBasicAuthentication(conID As String, user As String, pass As String) As String

 

Set Basic Authentication before establishing a connection to a webservice.

 

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

 

 

Parameters:

 

Name

Type

Description

conID

String

Identifier of existing htmlConnection object

user

String

User password or token to authenticate with the targeted webservice 

pass

String

Password to authenticate with the targeted webservice.
Some webservices only require a user token, but no password. For such cases we use a * as password (star symbol)

 

Returns:

 

Type

Value

Description

String

OK

The authentication header has been set

String

ERROR

Setting of the authentication header failed

 

Available in:

 

WindowMain

WindowLink

YES

NO

 

 

Example XojoScript:

 

// Test basic authentication to a webservice

 

// Declare variables

Dim user, password As String

 

// Instantiate htmlConnection object

Dim conID As String = htmlConnection

 

If conID = "ERROR" Then

MsgBox("RequestHeader : " + conID)

Return

End If

 

// Define credentials

user     = "9a1bc90e-3f2c-499d-9baa-66c11510c204" // required token

password = "*"  // test.nwscloud.ch accepts any password

 

// Define path to test webservice

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

 

// Authenticate with the webservice

Call htmlbasicAuthentication(conID,user,password)

 

// Send a GET Request to the webservice

Dim json As String = htmlsendSync(conID,"GET", url,15)

 

// Show response. Expected response: OK or FAIL

MsgBox(json)

 

// Close connection to webservice

Call htmlConnectionClose(conID)