Hybrid app: change user HTTP header with AngularJS

I am writing a hybrid app with Cordova and Ionic. My problem is that I want to access the server using an http request and I need to change the device user agent to pass the secret key.

 $http({
        method: 'GET',
        url: 'https://my-server.com/service/',
        headers: {
            'User-Agent' : 'app_name/2.0 (iOS 8.1) secret=75456789087654', 
            }
     }).success(function(data){
        alert(data.content);
    }).error(function(){
        alert("error");
        });

      

But when I look at the server logs, the user agent hasn't changed:

"GET / service HTTP / 1.1" - "Mozilla / 5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit (KHTML, like Gecko) Chrome Safari" " https://my-server.com/service/ " ...

How do I change the title?

+3


source to share


1 answer


I have the same problem. I think I am going to create a Cordova plugin to handle http requests and use that instead of $ http. This way I have complete control over the headers that I send.



0


source







All Articles