Main Content

matlab.net.http.field.AuthenticateField 类

命名空间: matlab.net.http.field
超类: matlab.net.http.HeaderField

HTTP WWW-Authenticate 或 Proxy-Authenticate 标头字段

描述

AuthenticateField 对象包含来自服务器的一个或多个要求提供身份验证信息的质询。服务器或代理会在响应消息中创建 AuthenticateField

在以下情况下,当您向要求进行身份验证的服务器或通过要求进行身份验证的代理发送请求消息时,MATLAB® 将自动尝试向服务器或代理进行身份验证:

  • HTTPOptions.Authenticate 属性为 true(默认值)

  • HTTPOptions.Credentials 属性包含必要的用户名和密码。

如果身份验证成功,则响应消息返回 OK 状态,且不包含身份验证字段。

如果您禁用身份验证或者身份验证失败,则响应消息将返回身份验证字段。在这种情况下,响应消息的状态代码为 401 (Unauthorized) 或 407 (ProxyAuthenticationRequired)。请检查 AuthInfo 对象,并通过为包含凭据的请求消息添加相应的 AuthorizationField 来进行响应。或者通过在 HTTPOptions 中设置正确的 Credentials 属性,重新发送请求。

如果服务器或代理要求的身份验证方案不受 MATLAB 支持,您必须自己实现身份验证协议。请使用相应的凭据和其他信息创建请求消息。

类属性

Sealed
true

有关类属性的信息,请参阅类属性

创建对象

描述

示例

obj = matlab.net.http.field.AuthenticateField(name,value) 创建一个身份验证标头字段,并将 Name 属性设置为 name,将 Value 属性设置为 value

服务器会在响应消息中创建此字段。可将此构造函数用于测试目的。

属性

全部展开

标头字段名称,指定为 'WWW-Authenticate''Proxy-Authenticate'

属性:

GetAccess
public
SetAccess
public

逗号分隔的质询列表,指定为 matlab.net.http.AuthInfo 对象向量,或采用 Internet Engineering Task Force (IETF®) 网站上的 RFC 7235 Hypertext Transfer Protocol (HTTP/1.1):Authentication 和 RFC 2617 HTTP Authentication:Basic and Digest Access Authentication 所定义的格式的字符串。可使用 AuthenticateField.convert 方法解析此字段。

属性:

GetAccess
public
SetAccess
public
Dependent
true

方法

全部展开

示例

全部折叠

此示例说明如何在请求消息中设置身份验证方案。

指定图像 URL

import matlab.net.*;
import matlab.net.http.*;

httpsUrl = "https://requestserver.mathworks.com";
uri = URI(strcat(httpsUrl, "/assets/computerVision.jpg?authenticate=digest"));

设置凭据

将身份验证方案设置为 Digest,并提供登录凭据。

cred = Credentials("Scheme", "Digest", "Username", "testName", "Password", "testPass");
options = HTTPOptions;
options.Credentials = cred;
options.Authenticate = false;
req = RequestMessage('GET');
response = req.send(uri, options);
authenticateField = response.getFields("WWW-Authenticate");
disp(authenticateField)
  AuthenticateField with properties:

     Name: "WWW-Authenticate"
    Value: "Digest realm="Digest Authentication",qop="auth",nonce="0.3598425461739989",opaque="0d3ced1a5756977875a15f93cc12dd21""

版本历史记录

在 R2016b 中推出