$ http取消设置默认标头

时间:2017-11-15 20:34:07

标签: javascript angularjs http

我有拦截服务为我的所有请求添加标头。但有时候我不需要这个标题,所以按照Angular的文档我将它设置为undefined

$http({
    url: 'https://hooks.slack.com/services/',
    method: 'POST',
    data: {test: 'test message'},
    headers: {
        'my-header': undefined
    }
})

但我仍然得到Request header field my-header is not allowed by Access-Control-Allow-Headers in preflight response

我做错了什么?

更新: 我尝试将标题设置为{},我尝试将Content-type设置为text/plainapplication/x-www-form-urlencoded,这不应该触发预检。但显然是因为自定义标题是my-header仍然是飞行前的标题。

0 个答案:

没有答案