Main Content

matlab.net.http.StatusCode Class

Namespace: matlab.net.http

Status code in HTTP response

Description

The StatusCode enumeration class provides identifiers for status codes. This list is from the 2018-09-21 version of the IANA HTTP Status Code registry, https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml.

Integer Represen-
tation
Enumeration Member NameInteger Represen-
tation
Enumeration Member NameInteger Represen-
tation
Enumeration Member Name
100Continue400BadRequest500InternalServerError
101SwitchingProtocols401Unauthorized501NotImplemented
102Processing402PaymentRequired502BadGateway
103EarlyHints403Forbidden503ServiceUnavailable
200OK404NotFound504GatewayTimeout
201Created405MethodNotAllowed505HTTPVersionNotSupported
202Accepted406NotAcceptable506VariantAlsoNegotiates
203NonAuthoritativeInformation407ProxyAuthenticationRequired507InsufficientStorage
204NoContent408RequestTimeout508LoopDetected
205ResetContent409Conflict509Unassigned
206PartialContent410Gone510NotExtended
207MultiStatus411LengthRequired511HTTPVersionNotSupported
208AlreadyReported412PreconditionFailed451UnavailableForLegalReasons
226IMUsed413PayloadTooLarge  
  414URITooLong  
300MultipleChoices415UnsupportedMediaType  
301MovedPermanently416RangeNotSatisfiable  
302Found417ExpectationFailed  
303SeeOther421MisdirectedRequest  
304NotModified422UnprocessableEntity  
305UseProxy423Locked  
306SwitchProxy424FailedDependency  
307TemporaryRedirect426UpgradeRequired  
308PermanentRedirect428PreconditionRequired  
  429TooManyRequests  
  431RequestHeaderFieldsTooLarge  

Methods

expand all

Examples

collapse all

Use the status code to provide error information.

Send a PUT message to the mathworks.com website.

uri = matlab.net.URI('https://www.mathworks.com');
header = matlab.net.http.field.ContentTypeField('text/plain');
req = matlab.net.http.RequestMessage('put',header,'Data');
resp = send(req, uri);

The website does not allow PUT methods. Display a user-friendly message.

sc = resp.StatusCode;
if sc ~= matlab.net.http.StatusCode.OK
    disp([getReasonPhrase(getClass(sc)),': ',getReasonPhrase(sc)])
    disp(resp.StatusLine.ReasonPhrase)
end
Client Error: Method Not Allowed
Method Not Allowed

The StatusCode methods - char, string, getReasonPhrase, and getClass - provide information about the code and its meaning. Choose a method based on your requirements.

Suppose that your response message contains status code 307. To run this example, create the code.

sc = matlab.net.http.StatusCode(307);

Use the char and the getReasonPhrase methods to return text for the status code meaning. The getReasonPhrase method creates a phrase you can use in messages.

txt = char(sc)
txt = 
'TemporaryRedirect'
msg = getReasonPhrase(sc)
msg = 
'Temporary Redirect'

Use the string method to return the integer value of the status code as a string.

value = string(sc)
value = 
"307"

If your code processes status codes based on status class, use the getClass method.

class = getClass(sc)
class = 
  StatusClass enumeration

    Redirection

enumeration matlab.net.http.StatusCode
Enumeration members for class 'matlab.net.http.StatusCode':

    Continue
    SwitchingProtocols
    Processing
    EarlyHints
    OK
    Created
    Accepted
    NonAuthoritativeInformation
    NoContent
    ResetContent
    PartialContent
    MultiStatus
    AlreadyReported
    IMUsed
    MultipleChoices
    MovedPermanently
    Found
    SeeOther
    NotModified
    UseProxy
    SwitchProxy
    TemporaryRedirect
    PermanentRedirect
    BadRequest
    Unauthorized
    PaymentRequired
    Forbidden
    NotFound
    MethodNotAllowed
    NotAcceptable
    ProxyAuthenticationRequired
    RequestTimeout
    Conflict
    Gone
    LengthRequired
    PreconditionFailed
    PayloadTooLarge
    URITooLong
    UnsupportedMediaType
    RangeNotSatisfiable
    ExpectationFailed
    MisdirectedRequest
    UnprocessableEntity
    Locked
    FailedDependency
    UpgradeRequired
    PreconditionRequired
    TooManyRequests
    RequestHeaderFieldsTooLarge
    UnavailableForLegalReasons
    InternalServerError
    NotImplemented
    BadGateway
    ServiceUnavailable
    GatewayTimeout
    HTTPVersionNotSupported
    VariantAlsoNegotiates
    InsufficientStorage
    LoopDetected
    Unassigned
    NotExtended
    NetworkAuthenticationRequired

Version History

Introduced in R2016b