Documentation

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.

Construction

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

这些方法实现等效MATLAB®functionality for this class.

char

Cookie as character vector

string

Cookie as string

Attributes

Sealed true

Examples

expand 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 step is not shown in the example. Assume that the server responds to your request message with the following 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

Was this topic helpful?