Adr*_*HHH 6 web-testing load-testing visual-studio
我记录的Web性能测试有几个"String body"字段,我需要在运行时从Web测试请求插件中修改它们的内容.
"String body"字段不能直接从字段的各个字段和子字段中获得PreRequestEventArgs.
如何将"String body"字段读出来string并在修改之后将其写回?
要读出"String body"字段,请将请求主体强制转换为StringHttpBody使字符串可用的字段.要将其写回,请创建一个新StringHttpBody对象以包含更新的字符串,然后将其写入请求中.
使用插件我需要在Web性能测试中修改请求的"String body"字段.我可以使用以下代码访问内容:
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3115 次 |
| 最近记录: |