chenk chenk - 5 days ago 7
HTTP Question

How to Send timezone info to server with http request?

I would like to do some timezone specific date manipulation on server. But I don't want to send the timezone via request payload for each and every http request. Any other work around there for achieve this? I use asp.net Web API for backend and Angular 2 for front end.

Answer

To add a header to a specific request:

var headers = new Headers();
headers.append('MyHeaderName','MyHeaderValue')
http.post('http://myurl', {/*body*/}, { headers: headers })

Alternatively, you could extend the http class and add a header to every request automatically, see here for details:

What is httpinterceptor equivalent in angular2?

Comments