Modifying HTTP Requests using a script

Before starting with this tutorial, please have a look first at the Getting Started 

Done? Here we go.

The HTTP Request can be modified via the "httpReq" variable that is made available to every script.  Note that the instance of the httpReq variable is unique per script; it is not shared.  The httpReq variable has the following properties that you can modify (except the read-only ones, of cours) and methods that you can invoke.


  • Description

    use this variable to modify the outgoing HTTP Request.  To find out the methods supported by this variable, type out "httpReq." (without qoutes) in the editor. An intellisense window will popup after the "."

  • Methods
    • AddCookie(name,value)
    • AddFile(name,bytes,fileName)
    • AddFile (name,bytes,fileName,contentType)
    • AddFile(name,path)
    • httpReq.AddHeader(name,value)
    • httpReq.AddRequestBody(contentType,reqBody)
    • httpReq.ClearCookies()
    • httpReq.ClearHeaders()
    • httpReq.ClearRequestBody()
  • Readonly Properties
    • Attempts : int32
    • Cookies : Dictionary
    • hHttpHeaders : Dictionary
    • RequestBody : string
  • Read/Write Properties
    • Credentials : System.Net.ICredentials
    • DateFormat : string
    • IsSendingNameValuePairs : bool
    • Method : Verb
    • RequestFormat : ContentType
    • Timeout : int32
    • Uri : System.Uri

The script editor supports intellisense for the httpReq variable.  Just type-in "httpReq." (note the dot) and the intellisense pop up will appear.


Example usages:

Change the target URL

  #change the target URL.
    httpReq.Uri = Uri("http://myfoo:8080/svc/" + "whatever")

Add a new set of HTTP Headers

   #Clear all current HTTP Headers
    #Add new HTTP Headers

Change the HTTP VERB to POST

     #change the HTTP VERB.
    httpReq.Method = Verb.POST

Change the HTTP Post Request Body

    #Modify the HTTP Request body.  This is useful only when the 
    #httpReq.Method == Verb.POST or Verb.PUT

Site Map | Printable View | © 2008 - 2024 WCFStorm Solutions

Powered by mojoPortal | XHTML 1.0 | CSS | Design by styleshout