Javascript Angular 5-从请求中删除默认HTTP头
这里的问题是,每当我向服务器发出http post请求时。 这是我在“网络”选项卡中看到的内容Javascript Angular 5-从请求中删除默认HTTP头,javascript,angular,api,http-headers,angular5,Javascript,Angular,Api,Http Headers,Angular5,这里的问题是,每当我向服务器发出http post请求时。 这是我在“网络”选项卡中看到的内容 Accept: application/json, text/plain, */* Accept-Encoding: gzip, deflate, br Accept-Language: en,en-GB;q=0.9 Authorization: Bearer olxyiByY_efkTH_3WavjtTnm0GclhYws.... Connection: keep-alive Content-Typ
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en,en-GB;q=0.9
Authorization: Bearer olxyiByY_efkTH_3WavjtTnm0GclhYws....
Connection: keep-alive
Content-Type: application/json
我想把它移走
接受:application/json,text/plain,/根据我的要求。当我提出每个请求时,它会自动设置 这就是我设置标题的方式
public jwt() {
let headers = new HttpHeaders({ 'Authorization': 'Bearer ' + currentUser.access_token,
'x-mol-lang': 'en', 'Content-Type': 'application/json'});
return ({ withCredentials: true, headers: headers, reportProgress: true});
}
我正在创建一个服务,并调用jwt函数进行后期操作
_this.http.post(_this.url, body, _this.jwtService.jwt()).subscribe();
我希望在网络选项卡中显示的输出没有**接受:application/json、text/plain、/**
我有什么办法可以完成这个动作吗?为什么要这样做?它包括
*/*
,因此它将接受任何内容,服务器没有理由查看该标头并使用406拒绝它。对于下载api,服务器会因此抛出500错误。它产生了一个问题返回this.http.post(_this.url,body{responseType:'text'})
@edrich13-您应该修复API,使其不会阻塞一个完美的接受头。请尝试更改HttpInterceptor。导出类拦截器实现HttpInterceptor