SetCredentials
PowerScript function
Description
Sets the authentication credentials. Assuming that an acceptable
authentication scheme and credentials are already known or obtained (for
example, via getsupportscheme), this function sends the authentication
credential to the server or proxy before sending requests to the
server.
Applies to
HTTPClient object in Objects and Controls
Syntax
|
1 |
objectname.SetCredentials(Boolean isProxyAuth, int scheme, string user, string password) |
|
Argument |
Description |
|---|---|
|
objectname |
The name of the object from which you want to set the |
|
isProxyAuth |
Specifies whether the proxy or server requires True — The proxy requires authentication. The HTTP status False — The server requires authentication. The HTTP |
|
scheme |
The authentication scheme that is currently used. Values 0 — Automatic authentication (Automatically use one of 1 — Negotiate authentication 2 — NTLM authentication 3 — Passport authentication (Unvalidated, because 4 — Digest authentication 5 — Basic authentication |
|
user |
The user name for authentication. |
|
password |
The password for authentication. |
Return value
Integer.
If any argument’s value is null, returns null. Otherwise returns the
following error code.
-19 — Security protocol error. It may be caused by TLS1.3 protocol,
or by the cipher suite during the TLS handshake.
-22 — The request needs to be resent. Only the ResendPostRequest
function can be called at this time.
-24 — Failed to set the authentication scheme.
Examples
The following example specifies that the server requires
authentication, uses the Negotiate authentication scheme and sets the user
name and password.
|
1 2 3 4 5 6 7 |
string ls_User,ls_PassWord, ls_Url HTTPClient lhc_Client lhc_Client = Create HTTPClient ls_User = "guest" ls_PassWord = "guest" ls_Url = "https://testserver.com:8001/" lhc_Client.SetCredentials(False, 1, ls_user, ls_PassWord) |
The following example creates an HTTPClient object, and uses
pre-authentication to set credentials in the initial request to the
server.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
string ls_User,ls_PassWord,ls_Url long ll_rtn,ll_Code HTTPClient lhc_Client lhc_Client = Create HTTPClient ls_User = "guest" ls_PassWord = "guest" ls_Url = "https://csharpserver.appeon.com:8001/" //pre-authentication ll_rtn = lhc_Client.setcredentials( false,5, ls_User,ls_PassWord) messagebox("Basic SetCredentials( false, 0, user, pass )=",ll_rtn) ll_rtn = lhc_Client.SendRequest("GET", ls_Url ) ll_Code = lhc_Client.GetResponseStatusCode() |
The following example gets the authorization scheme and then set
credentials accordingly.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
HTTPClient lhc_Client lhc_Client = Create HTTPClient ls_User = "guest" ls_PassWord = "guest" ls_Url = "https://csharpserver.appeon.com:8001/" ll_rtn = lhc_Client.SendRequest( "Get",ls_Url) //get the supported scheme ll_rtn = lhc_Client.getsupportscheme(ref li_Scheme) if ll_rtn = 1 and UpperBound(li_Scheme) >= 1 Then ll_rtn = lhc_Client.SetCredentials(false, li_Scheme[1], ls_User, ls_PassWord) ll_rtn = lhc_Client.SendRequest("GET", ls_Url ) ll_Code = lhc_Client.GetResponseStatusCode() messagebox("SendRequest","code:"+string(ll_Code)) else messagebox("GetSupportScheme( Scheme )",ll_rtn) end if |
See also