HCR087¶
HttpClient.BaseAddress with a non-root path must end with /.
Why¶
Relative request URIs resolve against BaseAddress using RFC 3986 rules: the last path segment of the base is treated as a resource name and replaced. BaseAddress = "https://api.example.com/v1" combined with GetAsync("users") produces https://api.example.com/users, not https://api.example.com/v1/users — the v1 segment is silently dropped and every relative request hits the wrong endpoint.
Bad¶
client.BaseAddress = new Uri("https://api.example.com/v1");
var response = await client.GetAsync("users"); // GET https://api.example.com/users
Better¶
Terminate the base path with /:
client.BaseAddress = new Uri("https://api.example.com/v1/");
var response = await client.GetAsync("users"); // GET https://api.example.com/v1/users
Current Detection¶
The implementation reports BaseAddress assignments on a System.Net.Http.HttpClient receiver when the value is a constant absolute URI (a string literal or new Uri("literal")) whose path is non-root and does not end with /. Root-only URIs (https://api.example.com), URIs already ending in /, non-constant values, and custom BaseAddress lookalikes are skipped. Test code is skipped: types ending in Test/Tests, types carrying common test attributes, types deriving from a test-named base type, types in a Test, Tests, Testing, *Test, or *Tests namespace, and files under a test, tests, testassets, testapps, or acceptance directory.
Suppression¶
Suppress only when the trailing-segment drop is intended — for example when every request URI is absolute or begins with /. Prefer adding the slash; it is almost always the intended shape.