Execute an HTTP request
- Last Updated: May 13, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
To execute an HTTP request, you need a client object and a response
object. Use the OpenEdge.Net.HTTP.ClientBuilder class
to create a client object that implements the OpenEdge.Net.HTTP.IHttpClient interface. Then, call the Execute() method on the client object. The response
returned by the server application or service is copied to the response object. For
example:
|
ClientBuilder:Build():Client method is the
minimum you need to build an HTTP client; however, IHttpClient is a fluent interface, so you can decorate the object by
adding other methods in a chain as shown in the following example:
|
Use the SetRequestTimeout() method to
set a timeout value in seconds for the HTTP connection to be established. Use the
SetNumRetries() method to set the number of
attempts at making a connection.
Use a client library
The client object can also make use of a client library to set certain properties and
behaviors. This client object follows the
OpenEdge.Net.HTTP.IHttpClientLibrary interface and can be
created using the OpenEdge.Net.HTTP.ClientLibraryBuilder class. The
purpose of the library object is to set common options, many of which are related to
secure HTTP communications such as SSL cyphers, SSL protocols, and TLS-supported
groups. The library object can then be used by multiple IHttpClient
object instances for consistent operation. The following example shows how to create
and use a client library:
|
Note in the above example that the created oClient object makes use
of the client library via the UseLibrary(IHttpClientLibrary)
method. The ClientLibraryBuilder class supports decoration of the
generated Library object similar to the
ClientBuilder. The builder class also offers a
SetRequestTimeout() method which allows the client library to
take precedence over any value set via the HTTP client instance itself.
You can use the client and client library objects to: