logo
logo

Advanced HTTP control

The Web SDK allows the consumers to have full control over the requests, the responses and even the HTTPClient from the SDK.

Note

The client variable in the following code examples refers to the IMClient instance. When using the Web SDK, the variable name can be chosen freely, but it is also called client at instantiation in the documentation.

It is recommended to set the Accept header to application/json.

Using a custom DelegationHandler

To inject a custom DelegatingHandler, first create an implementation of the Stylelabs.M.Sdk.WebClient.Http.IDelegatingHandlerFactory interface.

To register the factory:

MClient.SetDelegatingHandlerFactory(myDelegationHandlerFactory);
Important

This should be the first thing after creating the IWebMClient instance. Once the client has executed its first HTTP request, the delegating handler will be re-used and the factory will not be called anymore.

Using a custom HTTPClient

To inject a custom HTTPClient, first create an implementation of the Stylelabs.M.Sdk.WebClient.Http.IHttpClientFactory interface.

To register the factory:

MClient.SetHttpClientFactory(myHttpClientFactory);
Important

This should be the first thing after creating the IWebMClient instance. Once the client has executed its first HTTP request, the HTTPClient will be re-used and the factory will not be called anymore.

Can we improve this article ? Provide feedback