I’m attempting to use the Capacitor HTTP plugin to make an API call to a hosted service that requires an Authorization
HTTP header with each request. This works when running in the browser (and when the HTTP plugin is replaced with plain fetch()
) but does not succeed when running on iOS.
The code is pretty straightforward:
const response = await CapacitorHttp.get({
url: url.toString(),
headers: {
'Authorization': `Token ${settings.token}`
}
});
When running on an iOS device (or simulator), I can attach the Safari dev tools and see the request being sent to the native plugin from the console and verify that the URL and headers are correct:
But the response data back from the server is very clear: “Authentication credentials were not provided”. It’s simply not getting that header. I have tried making the same request in a REST client and that message only shows when the header is missing (as in there’s a different error when the token is invalid).
Am I setting the header wrong? How it is supposed to be set?