This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

matlab.net.http.field.CookieField class

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

HTTP Cookie header field

Description

If there are cookies in a Set-Cookie field, then you can send them to a server by including a CookieField object in your request message. For more information, see RFC 6265 HTTP State Management Mechanism.

Class Attributes

Sealed

true

For information on class attributes, see Class Attributes.

Creation

obj = matlab.net.http.field.CookieField(value) creates a Cookie header field with the Value property set to value.

Properties

expand all

Header field name, specified as 'Cookie'.

Attributes:

GetAccess

public

SetAccess

public

Cookie, specified as a string.

Attributes:

GetAccess

public

SetAccess

public

Methods

expand all

Examples

collapse all

This example sends all cookies to a server. In practice, you would send only unexpired cookies.

If the initial exchange involves multiple messages for authentication and redirection, you might want to obtain the CookieInfo object from the history containing all these messages. For more information, see CookieInfo.collectFromLog.

r = matlab.net.http.RequestMessage;
resp = send(r,'https://www.mathworks.com');
setCookieFields = resp.getFields('Set-Cookie');
if ~isempty(setCookieFields)
   % fetch all CookieInfos from Set-Cookie fields and add to request
   cookieInfos = setCookieFields.convert;
   r = r.addFields(matlab.net.http.field.CookieField([cookieInfos.Cookie]));
end
resp = r.send('https://www.mathworks.com');

Introduced in R2016b