Problem with iOS and header API versioning
![](https://techprofile.blob.core.windows.net/images/WmBD9oL6a0-0MJb9XowEMg.png?8D95C2)
Stesvis
1,041
Reputation points
We have implemented API versioning using headers, so in HttpClient on the mobile app code (Xamarin Forms), we do something like this:
_myHttpClient.DefaultRequestHeaders.Add(CustomRequestHeaders.ApiVersion, "2");
In the backend, we have a UsersController
and a Users_v2Controller
, and we need to consume the method GetUsersByRole
.
UsersController:
[Authorize]
[RoutePrefix("api/Users")]
public class UsersController : BaseApiController
{
// ...
[HttpGet]
[Route("")]
public IHttpActionResult GetUsersByRole([FromUri] int clientId, [FromUri] string role)
{
if (ApiVersion == "2")
return RedirectToRoute("GetUsersByRole_v2", new { clientId = clientId, role = role });
return Ok ("V1 results");
}
// ...
}
Users_v2Controller:
[Authorize]
[RoutePrefix("api/Users")]
public class Users_v2Controller : BaseApiController
{
// ...
[HttpGet]
[Route("", Name = "GetUsersByRole_v2")]
public IHttpActionResult GetUsersByRole([FromUri] int clientId, [FromUri] string role)
{
return Ok ("V2 results");
}
// ...
}
Now, I am consuming the GET /api/users?clientId=1&role=Admin
with ApiVersion=2
from android, iOS and Postman to double check:
- Android: returns
V2 results
- Postman: returns
V2 results
- iOS: returns
401: unauthorized
but if i setApiVersion=1
it works and returnsV1 results
What could the problem be? Why would iOS say i am unauthorized?
Sign in to answer