Main Content

matlab.net.http.StatusCode 类

包: matlab.net.http

HTTP 响应中的状态代码

描述

StatusCode 枚举类为状态代码提供标识符。以下列表来自 2018-09-21 版本的 IANA HTTP 状态代码注册表 https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml

整数表示
形式
枚举成员名称整数表示
形式
枚举成员名称整数表示
形式
枚举成员名称
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  

方法

全部展开

示例

全部折叠

可使用状态代码提供错误信息。

mathworks.com 网站发送一条 PUT 消息。

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);

此网站不允许使用 PUT 方法。将显示一条对用户友好的消息。

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

StatusCode 方法 - charstringgetReasonPhrasegetClass - 提供有关代码及其含义的信息。可根据您的要求选择一种方法。

假定您的响应消息中包含状态代码 307。要运行此示例,请创建以下代码。

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

使用 chargetReasonPhrase 方法返回说明状态代码含义的文本。getReasonPhrase 方法创建可在消息中使用的短语。

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

使用 string 方法以字符串形式返回状态代码的整数值。

value = string(sc)
value = 
"307"

如果您的代码基于状态类来处理状态代码,请使用 getClass 方法。

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

版本历史记录

在 R2016b 中推出