I converted HAR file to Gatling simulations Scala script, but I have problem with extracting CSRF token from request header and which needs to be passed to POST requests. Below is snippet for one of the POST request.
private val headers_35 = Map(
"accept" -> "application/json",
"accept-language" -> "en",
"maxdataserviceversion" -> "3.0",
"pragma" -> "no-cache",
"sap-client" -> "100",
"sap-language" -> "EN",
"sap-passport" -> "2A54482A0300E60000756E64657465726D696E6564202020202020202020202020202020202020202000005341505F4532455F54415F557365722020202020202020202020202020202020756E64657465726D696E65645F737461727475705F302020202020202020202020202020202020200005756E64657465726D696E65642020202020202020202020202020202020202020363437444331324644333543343538324141354645343943363942303945433720202000076E14D0D2F5624FCA848A8158189A78CB0000000000000000000000000000000000000000000000E22A54482A",
"sec-ch-ua" -> """Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114""",
"sec-ch-ua-mobile" -> "?0",
"sec-ch-ua-platform" -> "Windows",
"sec-fetch-dest" -> "empty",
"sec-fetch-mode" -> "cors",
"sec-fetch-site" -> "same-origin",
"x-csrf-token" -> "Fetch",
"x-requested-with" -> "XMLHttpRequest",
"x-xhr-logon" -> """accept="iframe,strict-window,window""""
)
private val headers_98 = Map(
"accept" -> "application/json",
"accept-language" -> "en",
"content-type" -> "application/json",
"dataserviceversion" -> "1.0",
"maxdataserviceversion" -> "3.0",
"origin" -> "https://myfioripp.sap-finance.xxxx.xxxx.com:44305",
"pragma" -> "no-cache",
"sap-client" -> "100",
"sap-language" -> "EN",
"sap-passport" -> "2A54482A0300E60000756E64657465726D696E6564202020202020202020202020202020202020202000005341505F4532455F54415F557365722020202020202020202020202020202020756E64657465726D696E65645F737461727475705F302020202020202020202020202020202020200005756E64657465726D696E65642020202020202020202020202020202020202020464530373332333832443032344339364237353035364533343532433132324520202000076E14D0D2F5624FCA848A8158189A78CB0000000000000000000000000000000000000000000000E22A54482A",
"sec-ch-ua" -> """Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114""",
"sec-ch-ua-mobile" -> "?0",
"sec-ch-ua-platform" -> "Windows",
"sec-fetch-dest" -> "empty",
"sec-fetch-mode" -> "cors",
"sec-fetch-site" -> "same-origin",
"x-csrf-token" -> "XBNe5sErfHVqCnzY6Ja8EQ==",
"x-requested-with" -> "XMLHttpRequest",
"x-xhr-logon" -> """accept="iframe,strict-window,window""""
)
–This’s the first occurance of the CSRF Token from request_35 response headers
http("request_35")
.get("/sap/opu/odata/UI2/INTEROP/PersContainers(category='P',id='flp.settings.FlpSettings')?$expand=PersContainerItems&sap-cache-id=A6B728680E9841B14DB70350B30E166F")
.headers(headers_35)
.check(header("x-csrf-token").saveAs("csrftoken35"))
–This’s the request where we’re getting error as **> request_98: Failed to build request: No attribute named 'csrftoken35' is defined**
.
–Here i’m overriding x-csrf-token
values which’s extracted from request_35
. But still getting abover error.
http("request_98")
.post("/sap/opu/odata/UI2/INTEROP/PersContainers")
.headers(headers_98)
.header("x-csrf-token", "${csrftoken35}")
.body(RawFileBody("data/0098_request.json")).asJson
Pl can someone look at this issue and let’s know if any resolution for this.