How to force JSON Content-Type crossdomain


#1

Hi,

I’m writting a JSON post crossdomain, but it’s changed Content-Type automatically:

  $http({
            url: '/example/teste',
            dataType: 'json',
            method: 'POST',
            data: '',
            headers: {
                "Content-Type": "application/json"
            }

        }).success(function(response){
            //$scope.response = response;
        }).error(function(error){
            //$scope.error = error;
        });

when I call url localhost all is right, and I get:

Accept	application/json; charset=utf-8
Content-Type	application/json

but if I change to other domain like …

$http({
                url: 'http://localhost/example/teste',
                dataType: 'json',
                method: 'POST',
                data: '',
                headers: {
                    "Content-Type": "application/json"
                }

            }).success(function(response){
                //$scope.response = response;
            }).error(function(error){
                //$scope.error = error;
            });

I get this headers in post request:

Accept	application/json, text/plain, */*
Content-Type	text/plain; charset=UTF-8

I try to force

     delete $http.defaults.headers.post['Accept'];
     delete $http.defaults.headers.post['Content-Type'];
     $http.defaults.headers.post['Content-Type'] = 'application/json; charset=utf-8';

but always same result … why is changed content-type in cross domain?

Thx


#2

Hi, did you got any resolution on the same ?