Main Content

matlab.net.http.Cookie class

Package:matlab.net.http

HTTP cookie received from server

Description

TheCookieclass represents an HTTP cookie. You obtain aCookieobject from aSetCookieFieldheader in aResponseMessageobject. Then you send it back to the server in aRequestMessageCookieFieldheader.

Class Attributes

Sealed
true

For information on class attributes, seeClass Attributes.

Creation

Description

example

obj = matlab.net.http.Cookie(name,value)creates aCookieobject with the specifiednameandvalueproperties. Use this constructor for testing.

Properties

expand all

Cookie name, specified as a string.

Example:"SESSIONID"

Attributes:

GetAccess
public
SetAccess
private

Cookie value, specified as a string. The value only has meaning to the server that sent the cookie.

Example:"688412d8ed15f4a736dc6ab3"

Attributes:

GetAccess
public
SetAccess
private

Methods

expand all

Examples

collapse all

This example assumes a server returns specific values in the variableresponse. You cannot run this code in MATLAB. You can, however, use these coding patterns to test values from your web service responses.

Create a cookie objecttestcontaining values you expect from a server.

test = matlab.net.http.Cookie('cookie1','ID:33445566')
test = Cookie with properties: Name: "cookie1" Value: "ID:33445566"

Send a message to a server; this example does not show this code. Assume that the server responds to your request message with this information in theresponsemessage.

setCookieFields = response.getFields('Set-Cookie')
setCookieFields = SetCookieField with properties: Name: "Set-Cookie" Value: "cookie1=ID:33445566; Path=/"

Extract the cookie information.

cookieInfos = setCookieFields.convert;

Compare the cookie with your test cookie.

string(cookieInfos.Cookie) == string(test)
ans = 1

The cookies match.

Introduced in R2016b