Classe FormPostHttpBody
Representa um corpo de POST de formulário HTML com uma coleção de parâmetros de formulário.
Namespace: Microsoft.VisualStudio.TestTools.WebTesting
Assembly: Microsoft.VisualStudio.QualityTools.WebTestFramework (em Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)
Sintaxe
<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
Comentários
Esse tipo é um contêiner para informações que são usadas pelo método postar para enviar dados para o servidor em um corpo HTTP.Essa classe pode ser serializada.
Exemplos
Os exemplos de código a seguir mostram como um FormPostHttpBody adiciona parâmetros post de formulário ao corpo do texto a 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
Hierarquia de herança
System.Object
Microsoft.VisualStudio.TestTools.WebTesting.FormPostHttpBody
Acesso thread-safe
Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.
Consulte também
Referência
Namespace Microsoft.VisualStudio.TestTools.WebTesting