主要内容

matlab.net.http.HeaderField类

Package:matlab.net.http.

Header field of HTTP message

Description

Use theHeaderField类来实现HTTP消息的标题字段。该类提供了标题和MATLAB中字符串之间的转换®objects, arrays, and structures. Although you can set theHeaderFieldproperties to arbitrary values, HTTP header fields have constraints on the allowed characters.

TheName属性定义标题字段类型。MATLAB为常用字段提供子类matlab.net.http.。fieldpackage. To see a list of supported subclasses, call theHeaderField.displaySubclasses方法。

Creation

Description

example

obj = matlab.net.http.HeaderField(name,value)creates a header field with theNameproperty set toname和the价值property set to价值。Either argument can be an empty double,[]。You can specify several argument pairs in any order asname1,value1,...,nameN,valueN。如果是最后一个价值参数缺失,然后HeaderField把它视为空。

Properties

expand all

Header field name, specified as a string or character vector.Name确定字段的类型,它确定有效值价值property. If you setNameto[]要么an empty string, then价值is[]

如果此对象是实现特定标题字段类型的子类的实例,则该类强制执行对的约束Nameproperty.

例子:'Content-Type'

Attributes:

Getaccess.
民众
SetAccess
民众

标题字段值,指定为字符串或任何类型的类型Nameproperty.

When you read this property,价值是表示字段中值的字符串。

设置此属性时,价值is any type acceptable to the field based on theName属性和/或此对象的类。结果将转换为字符串。如果字段类型具有默认值,请设置价值一个空字符串(''要么细绳('')). If you specify an empty double,[], then the request message发送完全的methods do not add this field to the message.

例子:'text/html'

Attributes:

Getaccess.
民众
SetAccess
民众
依赖
真的

方法

expand all

Examples

collapse all

To create a Content-Type header field, use either theHeaderFieldclass or theContentTypeFieldclass constructor.

When you use theHeaderFieldclass constructor, you specify theNameproperty 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 = matlab.net.http.headerfield('Content-Type','text/plain');

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

f2 = matlab.net.http.field.ContentTypeField('text/plain');

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

f1 == f2
ans = 1

This example shows how to locate a specific header field缓存控制in a response from mathworks.com.

Send a message tomathworks.com

Request = matlab.net.http.requestmessage;Uri = matlab.net.uri('//www.tatmou.com/au/');响应=发送(请求,URI);

Search for缓存控制和display the value.

field = response.getFields('Cache-Control');价值= field.Value
价值= "max-age=14400"

提示

  • TheHeaderField构造函数创建类的字段HeaderField。To create a field of a class defined in thematlab.net.http.。field包,请使用子类构造函数。对于子类列表,请致电HeaderField.displaySubclasses方法。

    例如matlab.net.http.。field.DateFieldsubclass creates a Date header field. If you use theHeaderField类创建日期字段,DateFieldclass interprets and enforces the value, even thoughHeaderFieldis not an instance ofDateField。Likewise, if you convert the field value to a MATLAB约会时间价值,datefield.convert.Convert.method is used.

  • If theHeaderFieldconstructor rejects theName价值arguments, use theGenericField类构造函数。

Version History

Introduced in R2016b