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. class


Header field of HTTP message


Use the HeaderField class to implement a header field for an HTTP message. The class provides conversions between strings in the header and MATLAB® objects, arrays, and structures. Although you can set the HeaderField properties to arbitrary values, HTTP header fields have constraints on the allowed characters.

The Name property defines the header field type. MATLAB provides subclasses for commonly used fields in the package. To see a list of supported subclasses, call the HeaderField.displaySubclasses method.



obj =,value) creates a header field with the Name property set to name and the Value property set to value. Either argument can be an empty double, []. You can specify several argument pairs in any order as name1,value1,...,nameN,valueN. If the last value argument is missing, HeaderField treats it as empty.


expand all

Header field name, specified as a string or character vector. Name determines the type of the field, which determines valid values for the Value property. If you set Name to [] or an empty string, then Value is [].

If this object is an instance of a subclass implementing a specific header field type, then that class enforces constraints on the Name property.

Example: 'Content-Type'

Header field value, specified as a string or any type valid for the Name property.

When you read this property, Value is a string representing the value in the field.

When you set this property, Value is any type acceptable to the field based on the Name property and/or the class of this object. The result is converted to a string. If a field type has a default value, set Value to an empty string ('' or string('')). If you specify an empty double, [], the request message send and complete methods do not add this field to the message.

Example: 'text/html'


charReturn header fields as formatted character vector
convertConvert header field value to MATLAB type
convertLikeConvert header field value like another header field
displaySubclassesDisplay supported HeaderField subclasses
eqCompare two HeaderField arrays
isequalCompare two HeaderField arrays
parseParse header field value and return as strings
stringReturn header fields as formatted string


expand all

To create a Content-Type header field, use either the HeaderField class or the ContentTypeField class constructor.

When you use the HeaderField class constructor, you specify the Name property as 'Content-Type'. However, if you misspell the field name, you might not find out about the error until the server rejects the message. Some servers silently ignore unknown field names.

f1 ='Content-Type','text/plain');

Using the ContentTypeField class constructor is preferred because you cannot misspell the field name.

f2 ='text/plain');

If the Value properties are the same, then the fields are equal, regardless of which constructor you use.

f1 == f2
ans =    1

An HTTP response message contains multiple header fields. This example shows how to locate a specific header field, Cache-Control, in a response from

Send a message to

request =;
uri ='');
response = send(request,uri);

Search for Cache-Control and display the value.

field = response.getFields('Cache-Control');
value = field.Value
value = 


    "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"


  • The HeaderField constructor creates fields of class HeaderField. To create a field of a class defined in the package, use the subclass constructor instead. For a list of subclasses, call the HeaderField.displaySubclasses method.

    For example, the subclass creates a Date header field. If you use the HeaderField class to create a Date field, the DateField class interprets and enforces the value, even though HeaderField is not an instance of DateField. Likewise, if you convert the field value to a MATLAB datetime value, the DateField.convert method is used.

  • If the HeaderField constructor rejects the Name and Value arguments, use the GenericField class constructor instead.

Introduced in R2016b

Was this topic helpful?