Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Disable certain $http headers for an individual request #1587

Closed
groner opened this issue Nov 16, 2012 · 2 comments
Closed

Disable certain $http headers for an individual request #1587

groner opened this issue Nov 16, 2012 · 2 comments

Comments

@groner
Copy link
Contributor

groner commented Nov 16, 2012

I'm using $http with FormData to send multiple files, and I need to not set Content-Type, or the browser will not set Content-Type and the multipart boundary won't be known.

I can do this by saving, deleting, and restoring the header in $http.defaults.headers, but It would be a lot nicer to do $http.post(url, data, {headers: {'Content-Type': null}}).

@pkozlowski-opensource
Copy link
Member

@groner Kei, unless I'm missing something (which is probably the case!) it is already possible, check this jsFiddle: http://jsfiddle.net/4sCPp/4/

$http.post('/echo/json/', {}, {
        headers: {
            'Content-Type': undefined
        }
    });

Could you try to provide a bit more info about what is going on on your side?

@groner
Copy link
Contributor Author

groner commented Nov 17, 2012

This seems to be working fine now. I'm not sure what I did differently yesterday, but it's not happening now.

Here's what I'm doing if you're curious:

var fd = new FormData();
fd.append('foo', '123');

$http.post('/echo/json/', fd, {
    transformRequest: angular.identity,
    headers: {
        'Content-Type': undefined
    }
});

The request should include the header Content-Type: multipart/form-data; boundary=blahblahblah. I thought it sent Content-Type: application/xml when I tried this last, but I must have been doing something else different.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants