Main Content

matlab.net.http.field.CookieField Class

Namespace: 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 on the Internet Engineering Task Force (IETF®) website.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

Description

example

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
Dependent
true

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');

Version History

Introduced in R2016b