Angular 4/5中php getallheaders()函数的等价物是什么?
我需要获取请求标头,但我无法在Angular中找到它。
我只能获得Angular的响应头。
答案 0 :(得分:0)
请求:强>
请看这里:How to correctly set Http Request Header in Angular 2
拦截器:
export class Interceptor implements HttpInterceptor {
constructor() { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log(request.headers); // log request headers
let headers = request.headers // here you can get your headers
.set('Content-Type', 'application/json'));
const cloneReq = request.clone({ headers });
return next.handle(cloneReq);
}
}
<强>响应:强>
看这里: Angular 4.3.3 HttpClient : How get value from the header of a response?
http
.get<MyJsonData>('/data.json', {observe: 'response'})
.subscribe(resp => {
console.log(resp.headers); // log response headers
});