How to capture request params generated dynamically from GET request to correlate next POST request

While launching the SAP application, the initial two GET requests get param “sap-context-id” and the same needs to pass on to other upcoming requests.
The strange part is I am not getting the “sap-context-id” in the GET response, but I can see the same in the GET request params.
My query … Is it possible to capture the “sap-context-id” param from the GET request param so that I can save it to the variable and use it in the upcoming requests?
I appreciate your help.

Sample Request params

HTTP/1.1 302 Found
set-cookie: sap-login-XSRF_QM1=0; expires=Tue, 01-Jan-1980 00:00:01 GMT; path=/; SameSite=None; secure
set-cookie: sap-usercontext=sap-language=EN&sap-client=100; path=/; SameSite=None; secure
set-cookie: SAP_SESSIONID_QM1_100=mveVEzdw3Mv63vwXvgKj0wL6aydNAhHulIKRnCjLVyU%3d; path=/; SameSite=None; secure
content-type: text/html; charset=utf-8
content-length: 5
location: /sap/bc/ui2/flp?saml2=disabled&_sap-hash=JTIzU2hlbGwtaG9tZQ&sap-system-login=X&sap-system-login-cookie=X&**sap-contextid=**SID:ANON:IKAWEQQM1AS01_QM1_22:aK-vnihlk8JcmIebDTWefQVnZujrJlbmE8-etYjR-ATT
sap-server: true

As I see this is response from redirect and you data is in location header → The HyperText Transfer Protocol (HTTP) 302 Found redirect status response code indicates that the resource requested has been temporarily moved to the URL given by the Location header.
So you can easy get it from it - example of this in 28 line: