Main Content

matlab.net.http.HTTPException class

Package:matlab.net.http
Superclasses:MException

Exception thrown by HTTP services

Description

TheHTTPExceptionclass contains information about errors.

TheRequestMessage.sendmethod throws an HTTP exception when an error occursafterit 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 occursbeforetheRequestMessage.sendmethod attempts to send the message, then it throws a standardMExceptioninstead.

TheHTTPExceptiondescribes the error in theMException.causeproperty and returns a history of the transaction. TheHistoryproperty contains the message that was sent and the message that was received, if any.

Properties

expand all

Request message as completed, specified as amatlab.net.http.RequestMessage对象。Requestcontains 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财产。否则,the last entry in theHistoryproperty 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对象。

Attributes:

GetAccess
public
SetAccess
private

History of the transaction, specified as a vector ofmatlab.net.http.LogRecord对象.Historyonly contains messages whose headers were successfully sent or received. If an exception occurs when sending or receiving a message header, thenHistorydoes 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 theMessageBodyPayloadproperty and/orDataproperties might not be set.

Attributes:

GetAccess
public
SetAccess
private

Examples

collapse all

Send a message to the website in theurlvariable. This destination returns a message whosePayloadproperty contains an invalid JPEG image for Content-Typeimage/jpeg.

tryresp = RequestMessage().send(url);catcheifisa(e,'matlab.net.http.HTTPException') response = e.History(end).Response;if~isempty(response) data = response.Body.Data; payload = response.Body.Payloadendendend

Thepayloadvariable contains the bytes that were received as auint8vector. Since the Content-Type is not character-based, thedatavariable is empty.

Introduced in R2016b