Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

This feature relies on access to Wolfram Cloud.

is an object that represents a successful response to an HTTP request, with the specified body and default metadata.

represents a response to an HTTP request, including the specified body and metadata.

Details and OptionsDetails and Options

  • HTTPResponse is usually stored in a CloudObject or specified as the result in an APIFunction or FormFunction.
  • In HTTPResponse[body,], body can be a string, a byte array object, or a list of integer byte values.
  • The metadata in HTTPResponse is an association including the following possible elements:
  • "StatusCode"200HTTP status code
    "ContentType""text/html"MIME type for content
    "Cookies"{}cookies to handle (using CookieFunction)
    "Headers"{}a list of rules giving HTTP response headers
  • Properties of an HTTPResponse object can be accessed using HTTPResponse[]["prop"].
  • Possible properties include all metadata items, together with:
  • "Body"response body as a string
    "BodyByteArray"response body as a ByteArray object
    "BodyBytes"response body as a list of byte values
    "CharacterEncoding"character encoding in the response body (e.g. "UTF8")
    "Properties"list of available properties
    "StatusCodeDescription"plain text description of status code
  • HTTPResponse[][] gives an association with values of all properties.
  • HTTPResponse has the following option:
  • CharacterEncodingAutomaticcharacter encoding to apply to the response
  • The setting CharacterEncoding->"enc" specifies that the body in HTTPResponse[body,] should be encoded using the encoding enc before being returned from a server as an HTTP response.
  • The setting CharacterEncoding->None specifies that no change should be made to body before returning it.
  • The Automatic setting for the CharacterEncoding option will use an encoding given from the "ContentType" metadata property if it includes a charset specification (as in "text/html; charset=latin1"). It will also use an encoding from the "CharacterEncoding" metadata property. If no encoding is otherwise given, then the "UTF8" encoding is used for text-based MIME types and None for other MIME types.
  • If a specific encoding is given for the CharacterEncoding option, and the "ContentType" metadata property is a text-based MIME type, a charset specification will be automatically added to indicate the encoding to browsers.

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

Return a plain HTTPResponse:

Click for copyable input

Use an XMLTemplate to output a result:

Click for copyable input

Return arbitrary body and content type:

Click for copyable input

Force the browser to download the content:

Click for copyable input
Introduced in 2014