Show / Hide Table of Contents

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.

Inserting a header on requests to a specific domain:

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

TargetVersions
.NET Standard 2.0200.5 - 200.7
.NET200.5 - 200.7
.NET Windows200.5 - 200.7
.NET Android200.5 - 200.7
.NET iOS200.5 - 200.7
.NET Framework200.5 - 200.7
UWP200.5 - 200.7
In This Article
Back to top Copyright © 2022 Esri.