Description
Specifies the client certificate that will be used to access the server when sending a request.
Applies to
Syntax
objectname.SetClientCert ( string p12cert, string password )
objectname.SetClientCert ( string storeName, string certIssue, string certSN )
Argument |
Description |
---|---|
objectname |
The name of the object from which you want to set the client certificate. |
p12cert |
The client's private key and public key p12 or PFX certificate file path. |
password |
Password of p12 or PFX certificate. |
storeName |
A string that specifies the name of the certificate store. Its value is a predefined system store such as:
To search for a certificate, it will start from the store used by the current user; and then the store assigned to the local machine. |
certIssue |
A string that identifies the entity that has signed and issued the certificate. The key-value pairs are separated by "~r~n". |
certSN |
The serial number of the certificate. The issuer name and the serial number identify a unique certificate. |
Return value
Integer. The error codes are as follows:
1 -- Success.
-1 -- Failed to read certificate.
-2 -- Failed to import certificate, or the specified certificate is not found, or the specified certificate has no private key.
-3 -- The password is incorrect.
Usage
Only one client certificate can be set. If both of the above syntaxes are executed, the one last set will overwrite the one previously set.
You can use ClearClientCert to clear the client certificate that is set by SetClientCert.
Examples
This example uses the certificate stored on the local directory of the client:
ln_rtn = l_httpclient.SendRequest("GET", "https://test.appeon.com") If ln_rtn = -16 Then l_httpclient.SetClientCert("e:\\testclient.pfx", "123456"); l_httpclient.SendRequest("GET", "https://test.appeon.com") End If
ln_rtn = l_restclient.SendGetRequest("https://test.appeon.com") If ln_rtn = -27 Then l_restclient.SetClientCert("e:\\testclient.pfx", "123456"); l_restclient.SendGetRequest("https://test.appeon.com") End If
This example uses the certificate from the root certificate store:
ln_rtn = l_httpclient.SendRequest("GET", "https://test.appeon.com") ls_certSN = "0cbe" ls_certIssue = 'CN = AAA Certificate Services~r~nO = Comodo CA Limited~r~n L = Salford~r~n S = Greater Manchester~r~n C = GB' If ln_rtn = -16 Then l_httpclient.anonymousAccess = false l_httpclient.SetClientCert("root", ls_certIssue, ls_certSN); l_httpclient.SendRequest("GET", "https://test.appeon.com") End If
ln_rtn = l_restclient.SendGetRequest ("https://test.appeon.com") ls_certSN = "0cbe" ls_certIssue = 'CN = AAA Certificate Services~r~nO = Comodo CA Limited~r~n L = Salford~r~n S = Greater Manchester~r~n C = GB' If ln_rtn = -27 Then l_restclient.anonymousAccess = false l_restclient.SetClientCert("root", ls_certIssue, ls_certSN); l_restclient.SendGetRequest ("https://test.appeon.com") End If
See also
Description
Specifies the client certificate that will be used to access the server when sending a request.
Applies to
Syntax
objectname.SetClientCert ( string p12cert, string password )
objectname.SetClientCert ( string storeName, string certIssue, string certSN )
Argument |
Description |
---|---|
objectname |
The name of the object from which you want to set the client certificate. |
p12cert |
The client's private key and public key p12 or PFX certificate file path. |
password |
Password of p12 or PFX certificate. |
storeName |
A string that specifies the name of the certificate store. Its value is a predefined system store such as:
To search for a certificate, it will start from the store used by the current user; and then the store assigned to the local machine. |
certIssue |
A string that identifies the entity that has signed and issued the certificate. The key-value pairs are separated by "~r~n". |
certSN |
The serial number of the certificate. The issuer name and the serial number identify a unique certificate. |
Return value
Integer.
Always returns 1.
Usage
If both of the above syntax are executed, the program will take priority to use the certificate in the certificate store.
Examples
This example uses the certificate stored on the local directory of the client:
ln_rtn = l_OAuthClient.AccessToken (lnv_TokenRequest, lnv_TokenResponse) If ln_rtn = -16 Then l_TokenRequest.SetClientCert("e:\\testclient.pfx", "123456"); l_OAuthClient.AccessToken (lnv_TokenRequest, lnv_TokenResponse) End If
ln_rtn = l_OAuthClient.RequestResource(lnv_OAuthRequest, lnv_ResourceResponse) If ln_rtn = -16 Then l_OAuthRequest.SetClientCert("e:\\testclient.pfx", "123456"); l_OAuthClient.RequestResource(lnv_OAuthRequest, lnv_ResourceResponse) End If
This example uses the certificate from the root certificate store:
ln_rtn = l_OAuthClient.AccessToken (lnv_TokenRequest, lnv_TokenResponse) ls_certSN = "0cbe" ls_certIssue = 'CN = AAA Certificate Services~r~nO = Comodo CA Limited~r~n L = Salford~r~n S = Greater Manchester~r~n C = GB' If ln_rtn = -16 Then l_TokenRequest.anonymousAccess = false l_TokenRequest.SetClientCert("root", ls_certIssue, ls_certSN); l_OAuthClient.AccessToken(lnv_TokenRequest, lnv_TokenResponse) End If
ln_rtn = l_OAuthClient.RequestResource(lnv_OAuthRequest, lnv_ResourceResponse) ls_certSN = "0cbe" ls_certIssue = 'CN = AAA Certificate Services~r~nO = Comodo CA Limited~r~n L = Salford~r~n S = Greater Manchester~r~n C = GB' If ln_rtn = -16 Then l_OAuthRequest.anonymousAccess = false l_OAuthRequest.SetClientCert("root", ls_certIssue, ls_certSN); l_OAuthClient.RequestResource(lnv_OAuthRequest, lnv_ResourceResponse) End If
See also