Skip to main content

Introduction to HTTP Requests

Introduction to HTTP Requests

You create an instance of %Net.HttpRequestOpens in a new tab to send HTTP requests of various kinds and receive the responses. This object is equivalent to a web browser, and you can use it to make multiple requests. It automatically sends the correct cookies and sets the Referer header as appropriate.

To create an HTTP request, use the following general process:

  1. Create an instance of %Net.HttpRequestOpens in a new tab.

  2. Set properties of this instance to indicate the web server to communicate with. The basic properties are as follows:

    • Server specifies the IP address or machine name of the web server. The default is localhost.

      Note:

      Do not include http:// or https:// as part of the value of Server. This causes ERROR #6059: Unable to open TCP/IP socket to server http:/.

    • Port specifies the port to connect to. The default is 80.

  3. Optionally set other properties and call methods of your HTTP request, as described in Specifying Other HTTP Request Properties.

  4. Then send an HTTP request, by calling the Get() method or other methods of your instance of %Net.HttpRequestOpens in a new tab, as described in Sending the HTTP Request.

    You can make multiple requests from your instance, which will automatically handle cookies and the Referer header.

    Note:

    If you created this HTTP request for use with the production outbound adapter (EnsLib.HTTP.OutboundAdapterOpens in a new tab), then instead use the methods of that adapter to send the request.

  5. Use the same instance of %Net.HttpRequestOpens in a new tab to send additional HTTP requests if needed. By default, InterSystems IRIS® data platform keeps the TCP/IP socket open so that you can reuse the socket without closing and reopening it.

    For additional information, see Managing Socket Reuse.

The following shows a simple example:

 set request=##class(%Net.HttpRequest).%New()
 set request.Server="tools.ietf.org"
 set request.Https=1
 set request.SSLConfiguration="TEST"
 set status=request.Get("/html/rfc7158")

For information on the Https and SSLConfiguration properties, see Using SSL to Connect, later in this topic. Also, for a more complete version of this example, see Accessing the HTTP Response.

FeedbackOpens in a new tab