Im doing GET requests via Axios on NODE and one of the headers for the method has to contain timestamp, everything works except that timestamp does not change value after the first time its initialized.
Because the timestamp does not change that causes some issues with receiving the response after a certain amount of time.
let time = Date.now().toString()
headers: { "timestamp": time }
Because the time is also used for encryption of other variables sent via the request, the timestamp used for encryption and for headers has to be the same.
headers: { "timestamp": Date.now().toString() } Does not work.
This is my first post on StackOverFlow, I have no clue if any of this makes sense.
headers: { "timestamp": Date.now().toString() } should work, but as you said it's not working so try this workaround:
{
let time = Date.now().toString();
// insert your axios code here
// headers: { "timestamp": time }
}
{
let time = Date.now().toString();
// insert your encryption code here
}
The two time variables don't conflict with each other because they were initialised with let and only exist in their current scope, which is between the curly brackets. This code uses two variables, so the Date.now() function is called twice and therefore updates for the two different things you're doing.