matlab.net.http.StatusCode - Status code in HTTP response - MATLAB (original) (raw)
Main Content
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 Name | Integer Represen-tation | Enumeration Member Name | Integer Represen-tation | Enumeration Member Name |
---|---|---|---|---|---|
100 | Continue | 400 | BadRequest | 500 | InternalServerError |
101 | SwitchingProtocols | 401 | Unauthorized | 501 | NotImplemented |
102 | Processing | 402 | PaymentRequired | 502 | BadGateway |
103 | EarlyHints | 403 | Forbidden | 503 | ServiceUnavailable |
200 | OK | 404 | NotFound | 504 | GatewayTimeout |
201 | Created | 405 | MethodNotAllowed | 505 | HTTPVersionNotSupported |
202 | Accepted | 406 | NotAcceptable | 506 | VariantAlsoNegotiates |
203 | NonAuthoritativeInformation | 407 | ProxyAuthenticationRequired | 507 | InsufficientStorage |
204 | NoContent | 408 | RequestTimeout | 508 | LoopDetected |
205 | ResetContent | 409 | Conflict | 509 | Unassigned |
206 | PartialContent | 410 | Gone | 510 | NotExtended |
207 | MultiStatus | 411 | LengthRequired | 511 | HTTPVersionNotSupported |
208 | AlreadyReported | 412 | PreconditionFailed | 451 | UnavailableForLegalReasons |
226 | IMUsed | 413 | PayloadTooLarge | ||
414 | URITooLong | ||||
300 | MultipleChoices | 415 | UnsupportedMediaType | ||
301 | MovedPermanently | 416 | RangeNotSatisfiable | ||
302 | Found | 417 | ExpectationFailed | ||
303 | SeeOther | 421 | MisdirectedRequest | ||
304 | NotModified | 422 | UnprocessableEntity | ||
305 | UseProxy | 423 | Locked | ||
306 | SwitchProxy | 424 | FailedDependency | ||
307 | TemporaryRedirect | 426 | UpgradeRequired | ||
308 | PermanentRedirect | 428 | PreconditionRequired | ||
429 | TooManyRequests | ||||
431 | RequestHeaderFieldsTooLarge |
Methods
These methods specialize standard MATLABĀ® operators and functions for objects in this class.
char | Name of status code as character vector |
---|---|
string | Three-digit value of status code as string |
Examples
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 = 'TemporaryRedirect'
msg = getReasonPhrase(sc)
msg = 'Temporary Redirect'
Use the string
method to return the integer value of the status code as a string.
If your code processes status codes based on status class, use the getClass
method.
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