To read out the "String body" field, cast the request body to a StringHttpBody
which makes the string available. To write it back, create a new StringHttpBody
object to contain the updated string, then write it into the request.
Using a plugin I need to modify the "String body" field of a request in a web performance test. I can access the contents using the following code:
public override void PreRequest(object sender, PreRequestEventArgs e)
{
if ( e.Request.Body == null ) { return; }
StringHttpBody httpBody = e.Request.Body as StringHttpBody;
if ( httpBody == null ) { return; }
string body = httpBody.BodyString;
string updatedBody = UpdateBody(body);
StringHttpBody newBody = new StringHttpBody();
newBody.BodyString = updatedBody;
e.Request.Body = newBody;
}