Main Content

matlab.net.http.field.AuthorizationField class

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

HTTP Authorization or Proxy-Authorization header field

Description

An AuthorizationField object contains credentials in a request message in response to a challenge from a server in an AuthenticateField. The credentials are in the form of an AuthInfo object. For a description of these fields, see RFC 7235 section 4.2 and section 4.4.

MATLAB® automatically creates this field when:

  • HTTPOptions.Authenticate property is true (default) in a request message.

  • You have specified appropriate credentials in the HTTPOptions.Credentials property.

  • MATLAB supports the authentication scheme requested by the server.

You create this field explicitly when you disable automatic authentication or implement an unsupported authentication protocol. If you create this field explicitly, then set the Value property to a valid authorization string or an AuthInfo object.

To see the AuthorizationField that was sent to the server for automatic authentication, examine the completed request or history arguments returned by the RequestMessage.send method.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

Description

example

obj = matlab.net.http.field.AuthorizationField(name,value) creates an authorization header field with the Name property set to name and the Value property set to value. Create this field if you disabled automatic authentication or to implement an unsupported authentication protocol.

Properties

expand all

Header field name, specified as 'Authorization' or 'Proxy-Authorization'.

Attributes:

GetAccess
public
SetAccess
public

Authorization, specified as a valid authorization string or a matlab.net.http.AuthInfo object.

Attributes:

GetAccess
public
SetAccess
public
Dependent
true

Methods

expand all

Examples

collapse all

This example shows how to pass user name and password to a Web server.

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

httpsUrl = 'https://requestserver.mathworks.com';
cred = Credentials('Scheme', 'Digest', 'Username', 'testName', 'Password', 'testPass');
uri = URI(strcat(httpsUrl, '/assets/computerVision.jpg?authenticate=digest'));
options = HTTPOptions;
options.Credentials = cred;
req = RequestMessage('GET');
[~, completedRequest, ~] = req.send(uri, options);
authorizationField = completedRequest.getFields("Authorization");
disp(authorizationField)
  AuthorizationField with properties:

     Name: "Authorization"
    Value: "Digest username="testName",realm="Digest Authentication",nonce="0.10850025543344421",uri="/assets/computerVision.jpg?authenticate=digest",cnonce="3abc9b6ff07a1e6e6b261f50a40b16cd",nc=00000001,response="3bd7d2e24c3bf3e3e5ea78628c1ccf76",qop="auth",opaque="0d3ced1a5756977875a15f93cc12dd21""
import matlab.net.http.*
creds = Credentials('Username','MyName','Password','MyPassword');
options = HTTPOptions('Credentials', creds);
[response, request] = RequestMessage().send('http://myhost.com',options);
authorizationField = request.getFields('Authorization');
authInfo = authorizationField.convert;
disp(string(authInfo));
Introduced in R2016b