简体   繁体   中英

angularjs $http is forcing Content-type header

Im trying to post a form, using this:

$http({
                url: authUrl,
                method: 'POST',
                data: params,
                headers: {
                    'Content-type': 'application/x-www-form-urlencoded',
                    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
                }
            }).success($scope.getEmailData).error($scope.httpError);

but when i check in fiddler the content-type was sent as Content-Type: application/json;charset=UTF-8 application/x-www-form-urlencoded

is this a bug or am i missing something?

Try Content-Type instead of Content-type for the key.

Also, if params is undefined, it can cause issues. Try setting data to '' . ie.

$http({
            url: authUrl,
            method: 'POST',
            data: params || '',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
            }
        }).success($scope.getEmailData).error($scope.httpError);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM