HTTP Request get and post data

I am trying to first get the data using the http request and reading the x-csrf token value , saving it in a variable. Next sending another http request to the server this time with the put/patch request along with the x-csrf token received from the previous request. The issue i am facing is that between the two http requests the session changes and hence the x-csrf token value received from the first request is not useful in the second request. So how can we post the data maintaining the same session between the two requests?

@Mari if you could help me here ?