Skip to main content

Sending the HTTP Request

Sending the HTTP Request

After you have created the HTTP request, use one of the following methods to send it:

Delete()
method Delete(location As %String = "", 
              test As %Integer = 0, 
              reset As %Boolean = 1) as %Status {}

Issues the HTTP DELETE request.

Get()
method Get(location As %String = "", 
           test As %Integer = 0, 
           reset As %Boolean = 1) as %Status {}

Issues the HTTP GET request. This method causes the web server to return the page requested.

Head()
method Head(location As %String, 
            test As %Integer = 0, 
            reset As %Boolean = 1) as %Status {}

Issues the HTTP HEAD request. This method causes the web server to return just the headers of the response and none of the body.

Patch()
method Patch(location As %String = "", 
             test As %Integer = 0, 
             reset As %Boolean = 1) as %Status {}

Issues the HTTP PATCH request. Use this method to partial changes to an existing resource.

Post()
method Post(location As %String = "", 
            test As %Integer = 0, 
            reset As %Boolean = 1) as %Status {}

Issues the HTTP POST request. Use this method to send data to the web server such as the results of a form, or upload a file. For an example, see Sending Form Data.

Put()
method Put(location As %String = "", 
           test As %Integer = 0, 
           reset As %Boolean = 1) as %Status {}

Issues the HTTP PUT request. Use this method to upload data to the web server. PUT requests are not common.

Send()
method Send(type As %String, 
            location As %String, 
            test As %Integer = 0, 
            reset As %Boolean = 1) as %Status {}

Sends the specified type of HTTP request to the server. This method is normally called by the other methods, but is provided for use if you want to use a different HTTP verb. Here type is a string that specifies an HTTP verb such as "POST".

In all cases:

  • Each method returns a status, which you should check.

  • If the method completes correctly, the response to this request will be in the HttpResponse property.

  • The location argument is the URL to request, for example: "/test.html".

  • The location argument can contain parameters, which are assumed to be already URL-escaped, for example: "/test.html?PARAM=%25VALUE" sets PARAM equal to %VALUE.

  • Use the test argument to check that you are sending what you are expecting to send:

    • If test is 1 then instead of connecting to a remote machine, the method will just output what it would have send to the web server to the current device.

    • If test is 2 then it will output the response to the current device after issuing the HTTP request.

  • Each method automatically calls the Reset() method after reading the response from the server, except if test=1 or if reset=0.

    The Reset() method resets the %Net.HttpRequestOpens in a new tab instance so that it can issue another request. This is much faster than closing this object and creating a new instance. This also moves the value of the Location header to the Referer header.

For example:

 Set httprequest=##class(%Net.HttpRequest).%New()
 Set httprequest.Server="www.intersystems.com"
 Do httprequest.Get("/")

For other examples, see the class documentation for %Net.HttpRequestOpens in a new tab.

FeedbackOpens in a new tab