HTTP cookie received from server
Cookie class represents an HTTP cookie. You obtain a
Cookie object from a
SetCookieField header in a
ResponseMessage object. Then you send it back to the server in a
CookieField header. For a description of these objects, see RFC 6265 HTTP State
Management Mechanism on the Internet Engineering Task Force (IETF®) website.
For information on class attributes, see Class Attributes.
Name — Cookie name
Cookie name, specified as a string.
Value — Cookie value
Cookie value, specified as a string. The value only has meaning to the server that sent the cookie.
Specialized Operators and Functions
These methods specialize standard MATLAB® operators and functions for objects in this class.
Cookie as string as it appears in a header field
Cookie as character vector
Test for Expected Cookie Value
This example assumes a server returns specific values in the variable
response. You cannot run this code in MATLAB. You can, however, use these coding patterns to test values from your web
Create a cookie object
test containing values you expect from a
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 the
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