This isn't the end of the world, however it would be a nice to have.
Currently building a hybrid app using Ionic 2 and I am sending requests to a server API.
I would like to have the User Agent string report the app and version (along with platform), e.g MyApp V1.0 (iOS)
.
Currently I am sending requests like:
http.post(my_server_url, JSON.stringify(dataToSend), options)
The options object is constructed as:
let options = {
headers: myHeaders
};
With headers being constructed as:
let myHeaders = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('User-Agent', 'MyApp V1.0 (iOS)');
The user agent is constructed using platform specific data, the above is just a straight forward string for the purposes of this question.
The request works as expected, the data is received by the server and acted on accordingly. The server sends an appropriate request which is dealt with properly. However, when I check the headers that were actually sent, the User-Agent not the one I set.
For example, on an iPhone, I see the following User Agent (both checking via Safari developer tools, and also the server log):
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko)
Which is based on the wrapping webview that is being used. I am therefore guessing there is some mechanism that is preventing me overriding the user agent.
As part of the same App, I am uploading files and using the cordova file transfer plugin for that. I set the headers for that transfer (which isn't using Angular http), and the user agent is correctly reported in the server logs.
Therefore, as the question states, is there a way using Angular http to set a custom User-Agent header?