Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.net.http.Cookie class

Package: 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.

Construction

example

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

Properties

expand all

Cookie name, specified as a string.

Example: "SESSIONID"

Attributes:

GetAccesspublic
SetAccessprivate

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

Example: "688412d8ed15f4a736dc6ab3"

Attributes:

GetAccesspublic
SetAccessprivate

Methods

These methods implement the equivalent MATLAB® functionality for this class.

char

Cookie as character vector

string

Cookie as string

Attributes

Sealedtrue

Examples

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

Introduced in R2016b

Was this topic helpful?