matlab.net.http.HTTPException - Exception thrown by HTTP services - MATLAB (original) (raw)
Main Content
Namespace: matlab.net.http
Superclasses: MException
Exception thrown by HTTP services
Description
The HTTPException
class contains information about errors.
The RequestMessage.send
method throws an HTTP exception when an error occurs after it attempts to send a message. For instance, the method throws an exception when:
- Something fails during transmission and the server does not receive the message. Possible causes of failure include a network problem, timeout, or bad URI.
- The server receives the message, but something fails while it is sending a response.
- The server receives the message and sends a response, but the response cannot be converted based on its Content-Type. For example, a bad JSON string is received.
If an error occurs before the RequestMessage.send
method attempts to send the message, then it throws a standard MException
instead.
The HTTPException
describes the error in theMException.cause
property and returns a history of the transaction. TheHistory
property contains the message that was sent and the message that was received, if any.
Properties
Request message as completed, specified as a matlab.net.http.RequestMessage object. Request
contains the last message that was sent or would have been sent. If this message header was successfully sent, then it is the same as the last entry in theHistory.Request
property. Otherwise, the last entry in theHistory
property does not contain the message you attempted to send.
Attributes:
GetAccess | public |
---|---|
SetAccess | private |
URI for the last message that was sent or would have been sent, specified as amatlab.net.URI object.
Attributes:
GetAccess | public |
---|---|
SetAccess | private |
History of the transaction, specified as a vector of matlab.net.http.LogRecord objects. History
only contains messages whose headers were successfully sent or received. If an exception occurs when sending or receiving a message header, then History
does not contain that message. If an error occurs while sending or receiving the payload, or during conversion of the data to or from the payload, then theMessageBody
Payload
property and/or Data
properties might not be set.
Attributes:
GetAccess | public |
---|---|
SetAccess | private |
Examples
Send a message to the website in the url
variable. This destination returns a message whose Payload
property contains an invalid JPEG image for Content-Type image/jpeg
.
try
resp = RequestMessage().send(url);
catch e
if isa(e,'matlab.net.http.HTTPException')
response = e.History(end).Response;
if ~isempty(response)
data = response.Body.Data;
payload = response.Body.Payload
end
end
end
The payload
variable contains the bytes that were received as auint8
vector. Since the Content-Type is not character-based, thedata
variable is empty.
Version History
Introduced in R2016b