You configure the client-server connection using an object that
implements the MWHttpClientConfig
interface. This
interface defines these properties:
TimeoutMilliSeconds
determines
the amount of time, in milliseconds, the client waits for a response
before timing out
ResponseSizeLimit
determines the
maximum size, in bytes, of the response a client accepts.
The API provides a default implementation, MWHttpClientDefaultConfig
,
that is automatically used when an HTTP client is instantiated. To
modify the configuration, extend MWHttpClientDefaultConfig
and
pass it to the HTTP client constructor.
When you create a client connection using the default constructor, MWHttpClient()
,
an instance of MWHttpClientDefaultConfig
is automatically
used to configure the client-server connection. The default configuration
sets these connection properties:
TimeOutMs
= 120000
ResponseSizeLimit
= 64*1024*1024
(64
MB)
To change one or more connection properties:
Implement a custom connection configuration by extending
the MWHttpClientDefaultConfig
interface.
Create the client connection using one of the constructors that accepts a configuration object.
MWHttpClient(MWHttpClientConfig config)
MWHttpClient(MWHttpClientConfig config, MWSSLConfig
securityConfig)
This code sample creates a client connection with a timeout value of 1000 ms:
class MyClientConfig : MWHttpClientDefaultConfig { public override int TimeoutMilliSeconds { get { return 1000; } } } ... MWClient client = new MWHttpClient(new MyClientConfig()); ...
To implement a custom connection configuration extend the MWHttpClientDefaultConfig
interface.
The MWHttpClientDefaultConfig
interface has one
getter method for each configuration property.
To specify that a client times out after 1 s and can only accept 4 MB responses:
class MyClientConfig : MWHttpClientDefaultConfig { public override int TimeoutMilliSeconds { get { return 60000; } } public override int ResponseSizeLimit { get { return 4*1024*1024; } } }