FormPostHttpBody 类
更新:2007 年 11 月
表示具有窗体参数集合的 HTML 窗体发送正文。
命名空间: Microsoft.VisualStudio.TestTools.WebTesting
程序集: Microsoft.VisualStudio.QualityTools.WebTestFramework(在 Microsoft.VisualStudio.QualityTools.WebTestFramework.dll 中)
语法
声明
<SerializableAttribute> _
Public Class FormPostHttpBody _
Implements IHttpBody, ICloneable
用法
Dim instance As FormPostHttpBody
[SerializableAttribute]
public class FormPostHttpBody : IHttpBody,
ICloneable
[SerializableAttribute]
public ref class FormPostHttpBody : IHttpBody,
ICloneable
public class FormPostHttpBody implements IHttpBody, ICloneable
备注
此类型是一个信息容器,该容器由 POST 方法用于将数据提交回 HTTP 正文中的服务器。可以序列化此类。
示例
下面的代码示例演示 FormPostHttpBody 如何将窗体发送参数添加到 WebTestRequest 的正文。
namespace TestProject1
{
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.WebTesting;
using Microsoft.VisualStudio.TestTools.WebTesting.Rules;
public class MyCodedWebTest : WebTest
{
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest request1 = new WebTestRequest("https://localhost/MyWebSite");
request1.ThinkTime = 14;
ExtractHiddenFields rule1 = new ExtractHiddenFields();
rule1.ContextParameterName = "1";
request1.ExtractValues += new EventHandler<ExtractionEventArgs>(rule1.Extract);
yield return request1;
WebTestRequest request2 = new WebTestRequest("https://localhost/MyWebSite/Default.aspx");
request2.Method = "POST";
FormPostHttpBodyrequest2Body = new FormPostHttpBody();
request2Body.FormPostParameters.Add("__VIEWSTATE", "{{$HIDDEN1.__VIEWSTATE}}");
request2Body.FormPostParameters.Add("Button1", "Button");
request2Body.FormPostParameters.Add("TextBox1", "text entered");
request2.Body = request2Body;
yield return request2;
}
}
}
Option Strict Off
Option Explicit On
Imports Microsoft.VisualStudio.TestTools.WebTesting
Imports Microsoft.VisualStudio.TestTools.WebTesting.Rules
Imports System
Imports System.Collections.Generic
Namespace MyVBTestProject
Public Class MyCodedWebTest
Inherits ThreadedWebTest
Public Sub New()
MyBase.New
Me.PreAuthenticate = true
Me.Proxy = "myproxy.com:80"
End Sub
Public Overrides Sub Run()
Dim request1 As WebTestRequest = New WebTestRequest _
("https://localhost/MyWebSite")
request1.ThinkTime = 10
Dim rule1 As ExtractHiddenFields = New ExtractHiddenFields
rule1.ContextParameterName = "1"
AddHandler request1.ExtractValues, AddressOf rule1.Extract
MyBase.Send(request1)
Dim request2 As WebTestRequest = New WebTestRequest _
("https://localhost/MyWebSite/Default.aspx")
request2.Method = "POST"
Dim request2Body As FormPostHttpBody = New FormPostHttpBody
request2Body.FormPostParameters.Add("__VIEWSTATE", _
"{{$HIDDEN1.__VIEWSTATE}}")
request2Body.FormPostParameters.Add("Button1", "Button")
request2Body.FormPostParameters.Add("TextBox1", "Entered text")
request2.Body = request2Body
MyBase.Send(request2)
End Sub
End Class
End Namespace
继承层次结构
System.Object
Microsoft.VisualStudio.TestTools.WebTesting.FormPostHttpBody
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
另请参见
参考
Microsoft.VisualStudio.TestTools.WebTesting 命名空间