Skip to main content

Sending Form Data

Sending Form Data

An HTTP request can include either a request body or form data. To include a form data, use the following methods:

InsertFormData()

Inserts form data into the request. This method takes two string arguments: the name of the form item and the associated value. You can insert more than one value for a given form item. If you do so, the values receive subscripts starting with 1. Within other methods, you use these subscripts to refer to the intended value

DeleteFormData()

Deletes form data from the request. The first argument is the name of the form item. The second argument is the subscript for the value to delete; use this only if the request contains multiple values for the same form item.

CountFormData()

Counts the number of values associated with a given name, in the request.

IsFormDataDefined()

Checks whether a given name is defined

NextFormData()

Retrieves the name of the next form item, if any, after sorting the names via $Order().

For details on these methods, see the class documentation for %Net.HttpRequestOpens in a new tab.

Example 1

After inserting the form data, you generally call the Post() method. For example:

    Do httprequest.InsertFormData("element","value")
    Do httprequest.Post("/cgi-bin/script.CGI")

Example 2

For another example:

    Set httprequest=##class(%Net.HttpRequest).%New()
    set httprequest.SSLConfiguration="MySSLConfiguration"
    set httprequest.Https=1
    set httprequest.Server="myserver.com"
    set httprequest.Port=443
    Do httprequest.InsertFormData("portalid","2000000")
    set tSc = httprequest.Post("/url-path/")
    Quit httprequest.HttpResponse
FeedbackOpens in a new tab