【问题标题】:How to remove authorization header from request [duplicate]如何从请求中删除授权标头[重复]
【发布时间】:2016-12-12 11:51:40
【问题描述】:
【问题讨论】:
标签:
angularjs
jwt
cloudinary
【解决方案1】:
您将需要一个拦截器来检查请求的 url,如果匹配则清除标头。或者,您可以使用$http 配置参数。
使用参数:
$http.post('https://api.cloudinary.com/v1_1/' + someId + '/upload', data, { headers: {} });
使用拦截器:
.factory('cloudinaryInterceptor', function() {
return {
request: function(config){
var authHeader = config.headers('authorization');
//Check for the host
var regex = /api\.cloudinary\.com/i;
if(regex.test(config.url))
//Detach the header
delete config.headers.authorization;
return config;
}
}
});
记得在配置阶段推送拦截器
$httpProvider.interceptors.push('cloudinaryInterceptor');
【解决方案2】:
以前有人问过这个问题。答案可以在here找到。
当您开始使用自定义请求标头时,您将获得 CORS 预检。这是一个使用 HTTP OPTIONS 动词并包含多个标头的请求,其中一个是 Access-Control-Request-Headers,列出了客户端希望在请求中包含的标头。
您需要使用适当的 CORS 回复该 CORS 预检
标题使这项工作。其中之一确实是
访问控制允许标头。该标题需要包含相同的
值包含(或更多)的 Access-Control-Request-Headers 标头。