How to remove HTTP specific headers in Javascript

前端 未结 4 974
情歌与酒
情歌与酒 2020-12-31 04:41

Is it possible to, before sending a http message, remove some specific http headers using javascript / XmlHttpRequest ?

I\'m using a proprietary browser, so there\'s

相关标签:
4条回答
  • 2020-12-31 05:03

    Adam's answer didn't work for me. However, the following did:

    xhr.setRequestHeader('Authorization', ' ');
    

    notice, second parameter is a string containing a space instead of empty space. It does not remove header completely, but sets it to the empty string, which might be enough for some cases.

    0 讨论(0)
  • 2020-12-31 05:06

    Never done it, but in theory you could try:

    xhr.setRequestHeader('Authorization', null);
    

    There's also an unspecified removeRequestHeader() function in some implementations, you may want to give it a try as well.

    0 讨论(0)
  • 2020-12-31 05:08

    You could use the setRequestHeader method of the XmlHttpRequest object assuming your browser supports it, It is part of the W3C spec. It is also implemented by IE.

    var req = new XMLHttpRequest();
    req.setRequestHeader("Authorization", "");
    
    0 讨论(0)
  • 2020-12-31 05:20

    When I use jquery-file-upload, and want to remove the header in the options method, setting it to null or '' doesn't work for me. I use this instead:

    req.setRequestHeader("Authorization");

    0 讨论(0)
提交回复
热议问题