Main Content

matlab.net.http.Cookie Class

Namespace: matlab.net.http

HTTP cookie received from server

Description

The 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 RequestMessage CookieField header. For a description of these objects, see RFC 6265 HTTP State Management Mechanism on the RFC Editor website.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

Description

obj = matlab.net.http.Cookie(name,value) creates a Cookie object with the specified name and value properties. Use this constructor for testing.

example

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 variable response. 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 object test containing 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 the response message.

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.

Version History

Introduced in R2016b