Partager via


FormPostHttpBody Class

Represents an HTML form post body with a collection of form parameters.

Inheritance Hierarchy

Object
  Microsoft.VisualStudio.TestTools.WebTesting.FormPostHttpBody

Namespace:  Microsoft.VisualStudio.TestTools.WebTesting
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class FormPostHttpBody _
    Implements IHttpBody, ICloneable
[SerializableAttribute]
public class FormPostHttpBody : IHttpBody, 
    ICloneable
[SerializableAttribute]
public ref class FormPostHttpBody : IHttpBody, 
    ICloneable
[<SerializableAttribute>]
type FormPostHttpBody =  
    class 
        interface IHttpBody 
        interface ICloneable 
    end
public class FormPostHttpBody implements IHttpBody, ICloneable

The FormPostHttpBody type exposes the following members.

Constructors

  Name Description
Public method FormPostHttpBody Initializes a new instance of the FormPostHttpBody class.

Top

Properties

  Name Description
Public property ContentType Gets a value that indicates the content type of the data being sent.
Public property FormPostParameters Gets the list of FormPostParameters included in this FormPostHttpBody.

Top

Methods

  Name Description
Public method Clone Returns a deep copy of the FormPostHttpBody.
Public method Equals Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as the default hash function. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method WriteHttpBody Writes the HTTP body stream.

Top

Remarks

This type is a container for information that is used by the POST method for submitting data back to the server in a HTTP body. This class can be serialized.

Examples

The following code examples show how a FormPostHttpBody adds form post parameters to the body of the 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";
            FormPostHttpBody request2Body = 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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.VisualStudio.TestTools.WebTesting Namespace

IHttpBody

ICloneable

System.Runtime.Serialization

Other Resources

Working with Web Tests