Main Content

matlab.net.http.field.AuthenticateField class

Package:matlab.net.http.field
Superclasses:matlab.net.http.HeaderField

HTTP WWW-Authenticate or Proxy-Authenticate header field

Description

AnAuthenticateFieldobject contains one or more challenges from a server asking for authentication information. A server or proxy creates anAuthenticateFieldin a response message.

When you send a request message to a server or through a proxy that requires authentication, MATLAB®automatically tries to authenticate to the server or proxy when:

  • HTTPOptions.Authenticateproperty is true (default)

  • HTTPOptions.Credentialsproperty contains the necessary names and passwords.

If authentication is successful, then the response message returns anOKstatus and does not contain an authentication field.

If you disable authentication or if authentication failed, then the response message returns an authentication field. In that case, the status code of the response message is either 401 (Unauthorized) or 407 (ProxyAuthenticationRequired). Examine theAuthInfoobject and respond by adding the appropriateAuthorizationFieldto the request message containing your credentials. Or resend the request by setting the correctCredentialsproperty inHTTPOptions.

If the server or proxy requires an authentication scheme that MATLAB does not support, you must implement the authentication protocol yourself. Create a request message with the appropriate credentials and other information.

Class Attributes

Sealed
true

For information on class attributes, seeClass Attributes.

Creation

Description

example

obj = matlab.net.http.field.AuthenticateField(name,value)creates an authentication header field with theNameproperty set tonameand theValueproperty set tovalue.

A server creates this field in a response message. Use this constructor for test purposes.

Properties

expand all

Header field name, specified as'WWW-Authenticate'or'Proxy-Authenticate'.

属性:

GetAccess
public
SetAccess
public

A comma-separated list of challenges, specified as a vector ofmatlab.net.http.AuthInfo对象or a string in the format defined byRFC 7235andRFC 2617. Use theAuthenticateField.convertmethod to parse this field.

属性:

GetAccess
public
SetAccess
public
Dependent
true

Methods

expand all

Examples

collapse all

This example shows how to set the authentication scheme in a request message.

Specify Image URL

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

Set Credentials

Set the authentication scheme toDigestand provide login credentials.

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""

版本历史

Introduced in R2016b