Skip to main content

Sending an HTTP Request

This topic describes how to send HTTP requests (such as POST or GET).

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.

Providing Authentication

If the destination server requires login credentials, your HTTP request can include an HTTP Authorization header that provides the credentials. The following subsections provide the details:

If you are using a proxy server, you can also specify login credentials for the proxy server; to do so, set the ProxyAuthorization property; see Using a Proxy Server. For details, see the class documentation for %Net.HttpRequestOpens in a new tab.

Authenticating a Request When Using HTTP 1.0

For HTTP 1.0, to authenticate an HTTP request, set the Username and Password properties of the instance of %Net.HttpRequestOpens in a new tab. The instance then creates the HTTP Authorization header based on that username and password, using the Basic Access Authentication (RFC 2617Opens in a new tab). Any subsequent request sent by this %Net.HttpRequestOpens in a new tab will include this header.

Important:

Make sure to also use SSL (see Using SSL to Connect). In Basic authentication, the credentials are sent in base-64 encoded form and thus can be easily read.

Authenticating a Request When Using HTTP 1.1

For HTTP 1.1, to authenticate an HTTP request, in most cases, just set the Username and Password properties of the instance of %Net.HttpRequestOpens in a new tab. When an instance of %Net.HttpRequestOpens in a new tab receives a 401 HTTP status code and WWW-Authenticate header, it attempts to respond with an Authorization header that contains a supported authentication scheme. The first scheme that is supported and configured for InterSystems IRIS is used. By default, it considers these authentication schemes, in order:

  1. Negotiate (SPNEGO and Kerberos, per RFC 4559Opens in a new tab and RFC 4178Opens in a new tab)

  2. NTLM (NT LAN Manager Authentication Protocol)

  3. Basic (Basic Access Authentication as described in RFC 2617Opens in a new tab)

    Important:

    If there is a chance that Basic authentication will be used, make sure to also use SSL (see Using SSL to Connect). In Basic authentication, the credentials are sent in base-64 encoded form and thus can be easily read.

On Windows, if the Username property is not specified, InterSystems IRIS can instead use the current login context. Specifically, if the server responds with a 401 status code and a WWW-Authenticate header for SPNEGO, Kerberos, or NTLM, then InterSystems IRIS uses the current operating system username and password to create the Authorization header.

The details are different from the HTTP 1.0 case, as follows:

  • If authentication succeeds, InterSystems IRIS updates the CurrentAuthenticationScheme property of the %Net.HttpRequestOpens in a new tab instance to indicate the authentication scheme that it used for the most recent authentication.

  • If an attempt to get an authentication handle or token for a scheme fails, InterSystems IRIS saves the underlying error to the AuthenticationErrors property of the %Net.HttpRequestOpens in a new tab instance. The value of this property is a $LIST, in which each item has the form scheme ERROR: message

Negotiate and NTLM are supported only for HTTP 1.1 because these schemes require multiple round trips, and HTTP 1.0 requires the connection to be closed after each request/response pair.

Variations

If you know the authentication scheme or schemes allowed by the server, you can bypass the initial round trip from the server by including an Authorization header that contains the initial token for the server for a chosen scheme. To do this, set the InitiateAuthentication property of the %Net.HttpRequestOpens in a new tab instance. For the value of this property, specify the name of a single authorization scheme allowed by the server. Use one of the following values (case-sensitive):

  • Negotiate

  • NTLM

  • Basic

If you want to customize the authentication schemes to use (or change their order in which they are considered), set the AuthenticationSchemes of the %Net.HttpRequestOpens in a new tab instance. For the value of this property, specify a comma-separated list of authentication scheme names (using the exact values given in the previous list).

Specifying the Authorization Header Directly

For either HTTP 1.0 or HTTP 1.1 (if applicable to your scenario), you can specify the HTTP Authorization header directly. Specifically, you set the Authorization property equal to the authentication information required by the user agent for the resource that you are requesting.

If you specify the Authorization property, the Username and Password properties are ignored.

Enabling Logging for HTTP Authentication

To enable logging for the HTTP authentication, enter the following in the Terminal:

  set $namespace="%SYS"
  kill ^ISCLOG
  set ^%ISCLOG=2
  set ^%ISCLOG("Category","HttpRequest")=5

Log entries are written to the ^ISCLOG global. To write the log to a file (for easier readability), enter the following (still within the %SYS namespace):

 do ##class(%OAuth2.Utils).DisplayLog("filename")

Where filename is the name of the file to create. The directory must already exist. If the file already exists, it is overwritten.

To stop logging, enter the following (still within the %SYS namespace):

 set ^%ISCLOG=0
 set ^%ISCLOG("Category","HttpRequest")=0

Specifying Other HTTP Request Properties

Before you send an HTTP request (see Sending the HTTP Request), you can specify its properties, as described in the following sections:

You can specify default values for all properties of %Net.HttpRequestOpens in a new tab, as specified in the section listed last.

The Location Property

The Location property specifies the resource that you are requesting from the web server. If you set this property, then when you call the Get(), Head(), Post(), or Put() method, you can omit the location argument.

For example, suppose that you are sending an HTTP request to the URL http://machine_name/test/index.html

In this case, you would use the following values:

Example Properties for %Net.HttpRequest
Properties Value
Server machine_name
Location test/index.html

Specifying the Internet Media Type and Character Encoding

You can use the following properties to specify the Internet media typeOpens in a new tab (also called MIME type) and character encoding in your instance of %Net.HttpRequestOpens in a new tab and its response:

  • ContentType specifies the Content-Type header, which specifies the Internet media type of the request body. The default type is none.

    Possible values include application/json, application/pdf, application/postscript, image/jpeg, image/png, multipart/form-data, text/html, text/plain, text/xml, and many others. For an extensive list, see http://www.iana.org/assignments/media-typesOpens in a new tab.

  • The ContentCharset property controls the desired character set for any content of the request if the content is of type text (text/html or text/xml for example). If you do not specify this property, InterSystems IRIS uses the default encoding of the InterSystems IRIS server.

    Note:

    If you set this property, you must first set the ContentType property.

  • The NoDefaultContentCharset property controls whether to include an explicit character set for content of type text if you have not set the ContentCharset property. By default, this property is false.

    If this property is true, then if you have content of type text and if you have not set the ContentCharset property, no character set is included in the content type; this means that the character set iso-8859–1 is used for the output of the message.

  • The WriteRawMode property affects the entity body (if included). It controls how the body of the request is written. By default, this property is false and InterSystems IRIS writes the body in the encoding that is specified in the request headers. If this property is true, InterSystems IRIS writes the body in RAW mode (performing no translation of the character set).

  • The ReadRawMode property controls how the body of the response is read. By default, this property is false and InterSystems IRIS assumes that the body is in the character set specified in the response headers. If this property is true, InterSystems IRIS reads the body in RAW mode (performing no translation of the character set).

Using a Proxy Server

You can send an HTTP request via a proxy server. In order to set this up, specify the following properties of your HTTP request:

  • ProxyServer specifies the host name of the proxy server to use. If this property is not null, the HTTP request is directed to this machine.

  • ProxyPort specifies the port to connect to, on the proxy server.

  • ProxyAuthorization specifies the Proxy-Authorization header, which you must set if a user agent must authenticate itself with a proxy. For the value, use the authentication information required by the user agent for the resource that you are requesting. Also see Providing Login Credentials.

  • ProxyHTTPS controls whether the HTTP request is for an HTTPS page, rather than a normal HTTP page. This property is ignored if you have not specified a proxy server. This property changes the default port on the target system to 443, the proxy port. Also see Using SSL to Connect.

  • ProxyTunnel specifies whether to establish a tunnel through the proxy to the target HTTP server. If true, the request uses the HTTP CONNECT command to establish a tunnel. The address of the proxy server is taken from the ProxyServer and ProxyPort properties. If ProxyHttps is true, then once the tunnel is established, InterSystems IRIS negotiates the SSL connection. In this case, the Https property is ignored because the tunnel establishes a direct connection with the target system.

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

Using SSL to Connect

The %Net.HttpRequestOpens in a new tab class supports SSL connections. To send the request via SSL, do the following:

  1. Set the SSLConfiguration property to the name of the activated SSL/TLS configuration to use.

    For information on creating and managing SSL/TLS configurations, see InterSystems TCP Guide. The SSL/TLS configuration includes an option called Configuration Name, which is the string to use in this setting.

  2. Also do one of the following, depending on whether you are using a proxy server:

    • If you are not using a proxy server, set the Https property to true.

    • If you are using a proxy server, set the ProxyHTTPS property to true.

      In this case, to use an SSL connection to the proxy server itself, set the Https property to true.

Note that when you use an SSL connection to a given server, the default port on that server is assumed to be 443 (the HTTPS port). For example, if you are not using a proxy server and Https is true, this changes the default Port property to 443.

Also see Using a Proxy Server.

Server Identity Checking

By default, when an instance of %Net.HttpRequestOpens in a new tab connects to a SSL/TLS secured web server, it checks whether the certificate server name matches the DNS name used to connect to the server. If these names do not match, the connection is not permitted. This default behavior prevents “man in the middle” attacks and is described in RFC 2818Opens in a new tab, section 3.1; also see RFC 2595Opens in a new tab, section 2.4.

To disable this check, set the SSLCheckServerIdentity property to 0.

The HTTPVersion, Timeout, WriteTimeout, and FollowRedirect Properties

%Net.HttpRequestOpens in a new tab also provides the following properties:

  • HTTPVersion specifies the HTTP version to use when requesting a page. The default is "HTTP/1.1". You can also use the "HTTP/1.0".

  • Timeout specifies how long, in seconds, to wait for a response from the web server. The default is 30 seconds.

  • WriteTimeout specifies how long, in seconds, to wait for a write the web server to complete. By default it will wait indefinitely. The minimum accepted value is 2 seconds.

  • FollowRedirect specifies whether to automatically follow redirection requests from the web server (signalled by the HTTP status codes in the range 300–399). The default is true if you are using GET or HEAD; otherwise it is false.

Specifying Default Values for HTTP Requests

You can specify default values for all properties of %Net.HttpRequestOpens in a new tab.

  • To specify a default value that apply to all namespaces, set the global node ^%SYS("HttpRequest","propname") where "propname" is the name of the property.

  • To specify a default value for one namespace, go to that namespace and set the node ^SYS("HttpRequest","propname")

    (The ^%SYS global affects the entire installation, and the ^SYS global affects the current namespace.)

For example to specify a default proxy server for all namespaces, set the global node ^%SYS("HttpRequest","ProxyServer")

Setting and Getting HTTP Headers

You can set values for and get values of the HTTP headers.

Each of the following properties of %Net.HttpRequestOpens in a new tab contains the value of the HTTP header that has the corresponding name. These properties are automatically calculated if you do not set them:

  • Authorization

  • ContentEncoding

  • ContentLength (This property is read-only.)

  • ContentType (Specifies the Internet media typeOpens in a new tab (MIME type) of the Content-Type header.)

  • ContentCharset (Specifies the charset part of the Content-Type header. If you set this, you must first set the ContentType property.)

  • Date

  • From

  • IfModifiedSince

  • Pragma

  • ProxyAuthorization

  • Referer

  • UserAgent

The %Net.HttpRequestOpens in a new tab class provides general methods that you can use to set and get the main HTTP headers. These methods ignore Content-Type and other entity headers.

ReturnHeaders()

Returns a string containing the main HTTP headers in this request.

OutputHeaders()

Writes the main HTTP headers to the current device.

GetHeader()

Returns the current value for any main HTTP header that has been set in this request. This method takes one argument, the name of the header (not case-sensitive); this is a string such as Host or Date

SetHeader()

Sets the value of a header. Typically you use this to set nonstandard headers; most of the usual headers are set via properties such as Date. This method takes two arguments:

  1. The name of the header (not case-sensitive), without the colon (:) delimiter; this is a string such as Host or Date

  2. The value of that header

You cannot use this method to set entity headers or read-only headers (Content-Length and Connection).

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

Managing Keep-Alive Behavior

If you reuse the same instance of %Net.HttpRequestOpens in a new tab to send multiple HTTP requests, by default, InterSystems IRIS keeps the TCP/IP socket open so that InterSystems IRIS does not need to close and reopen it.

If you do not want to reuse the TCP/IP socket, set the SocketTimeout property to 0.

The SocketTimeout property of %Net.HttpRequestOpens in a new tab specifies the window of time, in seconds, during which InterSystems IRIS will reuse a given socket. This timeout is intended to avoid using a socket that may have been silently closed by a firewall. The default value for this property is 115. You can set it to a different value.

Handling HTTP Request Parameters

When you send an HTTP request (see Sending the HTTP Request), you can include parameters in the location argument; for example: "/test.html?PARAM=%25VALUE" sets PARAM equal to %VALUE.

You can also use the following methods to control how your instance of %Net.HttpRequestOpens in a new tab handles parameters:

InsertParam()

Inserts a parameter into the request. This method takes two string arguments: the name of the parameter and the value of the parameter. For example:

 do req.InsertParam("arg1","1")

You can insert more than one value for a given parameter. If you do so, the values receive subscripts starting with 1. Within other methods, you use these subscripts to refer to the intended value.

DeleteParam()

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

CountParam()

Counts the number of values that are associated with a given parameter.

GetParam()

Gets the value of a given parameter in the request. The first argument is the name of the parameter. The second argument is the default value to return if the request does not have a parameter with this name; the initial value for this default is the null value. The third argument is the subscript for the value to get; use this only if the request contains multiple values for the same parameter.

IsParamDefined()

Checks whether a given parameter is defined. This method returns true if the parameter has a value. The arguments are the same as for DeleteParam().

NextParam()

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

ReturnParams()

Returns the list of parameters in this request.

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

Including a Request Body

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

  1. Create an instance of %GlobalBinaryStreamOpens in a new tab or a subclass. Use this instance for the EntityBody property of your HTTP request.

    Note that %GlobalBinaryStreamOpens in a new tab is deprecated but is still supported for use in this way. It is not recommended to substitute a different stream class for this use case.

  2. Use the standard stream interface to write data into this stream. For example:

     Do oref.EntityBody.Write("Data into stream")

For example, you could read a file and use that as the entity body of your custom HTTP request:

 set file=##class(%File).%New("G:\customer\catalog.xml")
 set status=file.Open("RS")
 if $$$ISERR(status) do $System.Status.DisplayError(status)
 set hr=##class(%Net.HttpRequest).%New()
 do hr.EntityBody.CopyFrom(file)
 do file.Close()

Sending a Chunked Request

If you use HTTP 1.1, you can send an HTTP request in chunks. This involves setting the Transfer-Encoding to indicate that the message is chunked, and using a zero-sized chunk to indicate completion.

Chunked encoding is useful when the server is returning a large amount of data and the total size of the response is not known until the request is fully processed. In such a case, you would normally need to buffer the entire message until the content length could be computed (which %Net.HttpRequestOpens in a new tab does automatically).

To send a chunked request, do the following:

  1. Create a subclass of %Net.ChunkedWriterOpens in a new tab, which is an abstract stream class that defines an interface for writing data in chunks.

    In this subclass, implement the OutputStream() method.

  2. In your instance of %Net.HttpRequestOpens in a new tab, create an instance of your %Net.ChunkedWriterOpens in a new tab subclass and populate it with the request data that you want to send.

  3. Set the EntityBody property of your %Net.HttpRequestOpens in a new tab instance equal to this instance of %Net.ChunkedWriterOpens in a new tab.

    When you send the HTTP request (see Sending the HTTP Request), it calls the OutputStream() method of the EntityBody property.

In your subclass of %Net.ChunkedWriterOpens in a new tab, the OutputStream() method should examine the stream data, decide whether to chunk it and how to do so, and invoke the inherited methods of the class to write the output.

The following methods are available:

WriteSingleChunk()

Accepts a string argument and writes the string as non-chunked output.

WriteFirstChunk()

Accepts a string argument. Writes the appropriate Transfer-Encoding heading to indicate a chunked message, and then writes the string as the first chunk.

WriteChunk()

Accepts a string argument and writes the string as a chunk.

WriteLastChunk()

Accepts a string argument and writes the string as a chunk, followed by a zero length chunk to mark the end.

If non-null, the TranslateTable property specifies the translation table to use to translate each string as it is written. All of the preceding methods check this property.

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

Inserting, Listing, and Deleting Cookies

%Net.HttpRequestOpens in a new tab automatically manages cookies sent from the server; if the server sends a cookie, your instance of %Net.HttpRequestOpens in a new tab will return this cookie on the next request. (For this mechanism to work, you need to reuse the same instance of %Net.HttpRequestOpens in a new tab.)

Use the following methods to manage cookies within your instance of %Net.HttpRequestOpens in a new tab:

InsertCookie()

Inserts a cookie into the request. Specify the following arguments:

  1. Name of the cookie.

  2. Value of the cookie.

  3. Path where the cookie should be stored.

  4. Name of the machine from which to download the cookie.

  5. Date and time when the cookie expires.

GetFullCookieList()

Returns the number of cookies and returns (by reference) an array of cookies.

DeleteCookie()

Deletes a cookie from the request.

Remember that cookies are specific to an HTTP server. When you insert a cookie, you are using a connection to a specific server, and the cookie is not available on other servers.

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

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.

Creating and Sending Multipart POST Requests

To create and send a multipart POST request, use the %Net.MIMEPartOpens in a new tab classes, which are discussed more fully in Creating, Writing, and Reading MIME Messages. The following example sends a POST request with two parts. The first part includes file binary data, and the second part includes the file name.

ClassMethod CorrectWriteMIMEMessage3(header As %String) 
{
     // Create root MIMEPart
     Set RootMIMEPart=##class(%Net.MIMEPart).%New()

     //Create binary subpart and insert file data
     Set BinaryMIMEPart=##class(%Net.MIMEPart).%New()
     Set contentdisp="form-data; name="_$CHAR(34)_"file"_$CHAR(34)_"; filename="
                     _$CHAR(34)_"task4059.txt"_$CHAR(34)
     Do BinaryMIMEPart.SetHeader("Content-Disposition",contentdisp)

     Set stream=##class(%FileBinaryStream).%New()
     Set stream.Filename="/home/tabaiba/prueba.txt"
     Do stream.LinkToFile("/home/tabaiba/prueba.txt")

     Set BinaryMIMEPart.Body=stream
     Do BinaryMIMEPart.SetHeader("Content-Type","text/plain")

    // Create text subpart
    Set TextMIMEPart=##class(%Net.MIMEPart).%New()
    Set TextMIMEPart.Body=##class(%GlobalCharacterStream).%New()
    Do TextMIMEPart.Body.Write("/home/tabaiba/prueba.txt")

    // specify some headers
    Set TextMIMEPart.ContentType="text/plain"
    Set TextMIMEPart.ContentCharset="us-ascii"
    Do TextMIMEPart.SetHeader("Custom-header",header)

    // Insert both subparts into the root part
    Do RootMIMEPart.Parts.Insert(BinaryMIMEPart)
    Do RootMIMEPart.Parts.Insert(TextMIMEPart)

    // create MIME writer; write root MIME message
    Set writer=##class(%Net.MIMEWriter).%New()

    // Prepare outputting to the HttpRequestStream
    Set SentHttpRequest=##class(%Net.HttpRequest).%New()
    Set status=writer.OutputToStream(SentHttpRequest.EntityBody)
    if $$$ISERR(status) {do $SYSTEM.Status.DisplayError(status) Quit}

    // Now write down the content
    Set status=writer.WriteMIMEBody(RootMIMEPart)
    if $$$ISERR(status) {do $SYSTEM.Status.DisplayError(status) Quit}

    Set SentHttpRequest.Server="congrio"
    Set SentHttpRequest.Port = 8080

    Set ContentType= "multipart/form-data; boundary="_RootMIMEPart.Boundary
    Set SentHttpRequest.ContentType=ContentType

    set url="alfresco/service/sample/upload.json?"
            _"alf_ticket=TICKET_caee62bf36f0ea5bd51194fce161f99092b75f62"

    set status=SentHttpRequest.Post(url,0) 
    if $$$ISERR(status) {do $SYSTEM.Status.DisplayError(status) Quit}
}

Accessing the HTTP Response

After you send an HTTP request, the HttpResponse property of the request is updated. This property is an instance of %Net.HttpResponseOpens in a new tab. For details on working with this object, see Using an HTTP Response.

See Also

FeedbackOpens in a new tab