Exception thrown by HTTP services
HTTPException class contains information about errors.
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
method attempts to send the message, then it throws a standard
HTTPException describes the error in the
MException.cause property and returns a history of the transaction. The
History property contains the message that was sent and the message
that was received, if any.
Request — Request message as completed
Request message as completed, specified as a
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 the
History.Request property. Otherwise, the last entry in the
History property does not contain the message you attempted to send.
URI — URI for last message
URI for the last message that was sent or would have been sent, specified as a
History — History of transaction
History of the transaction, specified as a vector of
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 the
Payload property and/or
Data properties might
not be set.
Response Payload Not Valid Format for Content-Type
Send a message to the website in the
This destination returns a message whose
Payload property contains an
invalid JPEG image for Content-Type
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
payload variable contains the bytes that were received as a
uint8 vector. Since the Content-Type is not character-based, the
data variable is empty.