Fig Fig - 3 months ago 61
HTTP Question

HTTP interceptor headers

I'm trying to send in a specific header every time I'm doing a http request/post. But my problem is that I don't know if my interceptor actually works. Is there a way for me to check what headers I'm sending with my http?

//Service to send http

getTokenFromServer(data: Authentication): Observable <string>{
//const serverUrl = 'http://localhost/broadcast-mock-server/getToken.php';
const serverUrl = 'http://localhost:5000/token';

const headers = new HttpHeaders();
headers.append("Content-Type", "application/json");

const obs = new Subject<string>();

const formData = new FormData();
formData.append('broadcasttoken', '769bcc1c-eba1-4425-a711-a7619d0ab3f1');

formData.append('password', data.password);, formData, {headers: headers})
.subscribe((response: Response) => {

console.log("Status:" +response.status);
console.log("Message", response);
}, (error) => {
console.log("Error code from server: " +error.status, error);
return obs.asObservable();


Interceptor that intercepts every http request

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Get the auth header from the service.
const authHeader = this.tokenService.getToken();
// Clone the request to add the new header.
if(req["url"].indexOf("/token") > -1 || req["url"].indexOf("/authenticate") > -1){
//Don't add Authorization header
return next.handle(req);
const authReq = req.clone({headers: req.headers.set('Authorization', authHeader)});
return next.handle(authReq);
//Go to /authenticate
const secureReq = req.clone({url: req.url.replace('http://', 'https://localhost:5000/authenticate')});
return next.handle(secureReq);

Answer Source

Just check browser inspector

enter image description here

if you want from console you can call:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download