要读取“字符串正文”字段,请将请求正文转换为
StringHttpBody
这使得字符串可用。要将其写回,请新建
字符串HttpBody
对象以包含更新的字符串,然后将其写入请求中。
使用插件,我需要在web性能测试中修改请求的“字符串体”字段。我可以使用以下代码访问内容:
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;
}