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

Disable certain $http headers for an individual request #1587

Closed

Description

@groner

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}}).

Activity

  1. pkozlowski-opensource commented on Nov 17, 2012

    @pkozlowski-opensource
    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?

  2. groner commented on Nov 17, 2012

    @groner
    ContributorAuthor

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions