Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.net.http.StatusCode class

Package: matlab.net.http

Status code in HTTP response

Description

The StatusCode enumeration class provides identifiers for status codes.

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

Methods

fromValueCreate StatusCode object from string or number
getClassStatusClass for StatusCode
getReasonPhraseStatusCode identifier as text phrase

These methods implement the equivalent MATLAB® functionality for this class.

char

Name of status code as character vector

string

Three-digit value of status code as string

Examples

expand all

Use the status code to provide error information.

Send a PUT message to the mathworks.com website.

uri = matlab.net.URI('http://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
HTTP method PUT is not supported by this URL

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 = 
Redirection
enumeration matlab.net.http.StatusCode
Enumeration members for class 'matlab.net.http.StatusCode':

    Continue
    SwitchingProtocols
    Processing
    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
    InternalServerError
    NotImplemented
    BadGateway
    ServiceUnavailable
    GatewayTimeout
    HTTPVersionNotSupported
    VariantAlsoNegotiates
    InsufficientStorage
    LoopDetected
    Unassigned
    NotExtended
    NetworkAuthenticationRequired

Introduced in R2016b

Was this topic helpful?