com.HttpRequest.setCertificateAndKey
Specifies the certificate and key to use for the
HttpRequest
request.
Syntax
setCertificateAndKey(
certificate STRING,
privateKey STRING)
- certificate defines the absolute path of the certificate file (.crt).
- privateKey defines the absolute path of the private key file (.pem).
Usage
The setCertificateAndKey()
method allows you to define the certificate and key
to use for authentication for the current HttpRequest
.
For example, you can set the client certificate to use for an HTTPS connection at runtime instead of setting entries in the FGLPROFILE file before running the application.
When you use setCertificateAndKey()
, you automatically override FGLPROFILE entries for
security.global.certificate
and security.idsec.certificate
and the
security.global.privatekey
and security.idsec.privatekey
. To
return to using settings in the FGLPROFILE entries, you must use the corresponding clearCertificateAndKey() method.
Example
IMPORT com
MAIN
DEFINE req com.HttpRequest
DEFINE resp com.HttpResponse
LET req = com.HttpRequest.Create("https://myserver/")
CALL req.setMethod("GET")
CALL req.setCertificateAndKey("client.crt","client.key")
CALL req.setCipher("AES128-SHA256")
CALL req.setVerifyServer(FALSE)
TRY
CALL req.doRequest()
LET resp = req.getResponse()
DISPLAY resp.getStatusCode()
DISPLAY resp.getTextResponse()
CATCH
DISPLAY "ERROR :",status||" ("||sqlca.sqlerrm||")"
EXIT PROGRAM -1
END TRY
END MAIN
FGLPROFILE must have the Certificate Authority setting:
security.global.ca ="ca.crt"
In case of error, the method throws an exception and sets the
status
variable. Depending on the error, a human-readable description of the
problem is available in the sqlca.sqlerrm
register. See Error handling in GWS calls (status).