matlab.net.http.field.AuthorizationField - HTTP Authorization or Proxy-Authorization header field - MATLAB (original) (raw)
Namespace: 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 more information, see RFC 7235 section 4.2 Authorization and section 4.4 Proxy-Authorization on the RFC Editor website.
MATLABĀ® automatically creates this field when:
HTTPOptions.Authenticate
property istrue
(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 theValue
property to a valid authorization string or anAuthInfo
object.
To see the AuthorizationField
that was sent to the server for automatic authentication, examine the completed request or history arguments returned by theRequestMessage.send
method.
Creation
Description
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
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
addFields | Add fields to HeaderField array |
---|---|
removeFields | Remove fields from header field array |
changeFields | Change existing values in HeaderField array |
replaceFields | Change values in or add fields to array of HeaderFields |
getFields | Return header fields matching name or class |
eq | Compare two HeaderField arrays |
convertLike | Convert header field value like another header field |
parse | Parse header field value and return as strings |
displaySubclasses | Display supported HeaderField subclasses |
convert | Value property of AuthorizationField as vector of AuthInfo objects.There is only oneAuthInfo object in an AuthorizationField. If you pass in a vector of AuthorizationField objects,convert returns an equal-size vector of AuthInfo objects. The parameters in AuthInfo correspond to parameters of the credentials in the AuthorizationField. This set of parameters varies depending on the AuthInfo.Scheme property, which is the first token in the field. |
---|
These methods specialize standard MATLAB operators and functions for objects in this class.
isequal | true if two header field arrays are the same size and corresponding elements are equal, as described by eq method |
---|---|
string | Array of header fields as string, as it appears in a message. Inserts newline characters between fields but not at the end of all fields. |
char | Array of header fields as character vector, as described bystring method |
Examples
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));
Version History
Introduced in R2016b