HttpResponse Class
Use the HttpResponse class to handle the HTTP response returned by the Http class.
Use the XML classes or JSON Classes to parse XML or JSON content in the body of a response accessed by HttpResponse.
In the following getXmlStreamReader example, content is retrieved via an HTTP callout, then the XML is parsed using the XmlStreamReader class.
See Also
The following are methods for HttpResponse. All are instance methods.
-
Retrieves the body returned in the response.
-
Retrieves the body returned in the response as a Blob.
-
Retrieves the body returned in the response as a DOM document.
-
Retrieves the contents of the response header.
-
Retrieves an array of header keys returned in the response.
-
Retrieves the status message returned for the response.
-
Retrieves the value of the status code returned in the response.
-
Returns an
XmlStreamReaderthat parses the body of the callout response. -
Specifies the body returned in the response.
-
Specifies the body returned in the response using a Blob.
-
Specifies the contents of the response header.
-
Specifies the status message returned in the response.
-
Specifies the value of the status code returned in the response.
-
Returns the status message and status code returned in the response, for example:
Retrieves the body returned in the response.
public String getBody()
Type: String
Limit 6 MB for synchronous Apex or 12 MB for asynchronous Apex. The HTTP request and response sizes count towards the total heap size.
Retrieves the body returned in the response as a Blob.
public Blob getBodyAsBlob()
Type: Blob
Limit 6 MB for synchronous Apex or 12 MB for asynchronous Apex. The HTTP request and response sizes count towards the total heap size.
Retrieves the body returned in the response as a DOM document.
public Dom.Document getBodyDocument()
Type: Dom.Document
Use it as a shortcut for:
Retrieves the contents of the response header.
public String getHeader(String key)
- key: Type: String
Type: String
Retrieves an array of header keys returned in the response.
public String[] getHeaderKeys()
Type: String[]
Retrieves the status message returned for the response.
public String getStatus()
Type: String
Retrieves the value of the status code returned in the response.
public Integer getStatusCode()
Type: Integer
Returns an XmlStreamReader that parses the body of the callout response.
public XmlStreamReader getXmlStreamReader()
Type: System.XmlStreamReader
Use it as a shortcut for:
Specifies the body returned in the response.
public Void setBody(String body)
- body: Type: String
Type: Void
Specifies the body returned in the response using a Blob.
public Void setBodyAsBlob(Blob body)
- body: Type: Blob
Type: Void
Specifies the contents of the response header.
public Void setHeader(String key, String value)
Type: Void
Specifies the status message returned in the response.
public Void setStatus(String status)
- status: Type: String
Type: Void
Specifies the value of the status code returned in the response.
public Void setStatusCode(Integer statusCode)
- statusCode: Type: Integer
Type: Void
Returns the status message and status code returned in the response, for example:
public String toString()
Type: String