Interface IHttpMessageInterceptor
Defines an interface for intercepting and processing HTTP requests and responses made by the Maps SDK.
Namespace: Esri.ArcGISRuntime.Http
Assembly: Esri.ArcGISRuntime.dll
Syntax
public interface IHttpMessageInterceptor
Remarks
The IHttpMessageInterceptor allows you to intercept, monitor, and modify HTTP requests and responses. You can use it for various purposes, such as logging, tracing, modifying headers, or mocking responses.
Examples of usage:
- Logging:You can create an implementation that logs the request and response details, such as the request URI, HTTP method, response status code, and elapsed time. This can be useful for monitoring and debugging.
- Mocking:You can create an implementation that mocks the HTTP responses for automated testing scenarios. This allows you to simulate different response scenarios without actually making real network calls.
- Modifying Headers:You can create an implementation that modifies the request or response headers. For example, you can add custom headers, modify the user agent, or adjust the cache control settings.
To use an IHttpMessageInterceptor, create a class that implements this interface and register it using the UseHttpMessageInterceptor(IArcGISHttpConfiguration, IHttpMessageInterceptor) extension method on the IArcGISHttpConfiguration instance.
public class MyHttpListener : IHttpMessageInterceptor
{
public Task<HttpResponseMessage> SendAsync(HttpMessageInvoker invoker, HttpRequestMessage message, CancellationToken cancellationToken)
{
if(message.RequestUri?.Host == "mydomain.com")
{
message.Headers.Add("X-CustomHeader", "myHeaderValue");
}
return invoker.SendAsync(message, cancellationToken);
}
}
Methods
Name | Description |
---|---|
SendAsync(HttpMessageInvoker, HttpRequestMessage, CancellationToken) | Sends an HTTP request and returns the response. |
Applies to
Target | Versions |
---|---|
.NET Standard 2.0 | 200.5 - 200.6 |
.NET | 200.5 - 200.6 |
.NET Windows | 200.5 - 200.6 |
.NET Android | 200.5 - 200.6 |
.NET iOS | 200.5 - 200.6 |
.NET Framework | 200.5 - 200.6 |
UWP | 200.5 - 200.6 |