title: How to extract the X-XSRF_TOKEN in a web performance test
body: <p>I had written a web performance test which was earlier working fine. Developers now have added a CSRF token validation (to prevent CSRF attack on the website). After this the test has started to fail (Error, Bad Request). I dug into it and found that the server is generating an XSRF-TOKEN on login request which has to be passed in every request there after. 
  Now to extract the token we need to parse response to the login request. How can we do it?</p>
  
  <p>My coded tests looks like this:</p>
  
  <pre><code>WebTestRequest request4 = new WebTestRequest("https://servertest:8080/WebConsole/Account/Login");
  request4.Method = "POST";
  request4.Headers.Add(new WebTestRequestHeader("Accept", "application/json, text/plain, */*"));
  request4.Headers.Add(new WebTestRequestHeader("Referer", "https://servertest:8080/WebConsole/index.html#/"));
  StringHttpBody request4Body = new StringHttpBody();
  request4Body.ContentType = "application/json;charset=utf-8";
  request4Body.InsertByteOrderMark = false;
  request4Body.BodyString = "{\"UserName\":\"pkdomain\\\\administrator\",\"Password\":\"sqa@123\"}";
  request4.Body = request4Body;
  yield return request4;
  request4 = null;
  
  WebTestRequest request5 = new WebTestRequest("https://servertest:8080/WebConsole/scripts/home/Pages/home-view.html");
  request5.ThinkTime = 4;
  request5.Headers.Add(new WebTestRequestHeader("Accept", "text/html"));
  request5.Headers.Add(new WebTestRequestHeader("Referer", "https://servertest:8080/WebConsole/index.html#/"));
  yield return request5;
  request5 = null;
  </code></pre>