Main Content

matlab.net.http.headerfield类

包裹:matlab.net.http

HTTP消息的标题字段

描述

使用Headerfieldclass to implement a header field for an HTTP message. The class provides conversions between strings in the header and MATLAB®对象,阵列和结构。虽然您可以设置Headerfield属性到任意值,HTTP标头字段对允许的字符具有约束。

姓名property defines the header field type. MATLAB provides subclasses for commonly used fields in thematlab.net.http.field包裹。要查看支持子类的列表,请致电万博1manbetxheaderfield.displaysubclasses方法。

创建

描述

例子

obj = matlab.net.http.headerfield(名称,值)姓名属性设置为姓名Value属性设置为value。任何一个参数都可以是一个空的双重,[]。您可以按任何顺序指定几个参数对NAME1,Value1,...,Namen,Valuen。如果是lastvalueargument is missing, thenHeaderfield将其视为空。

特性

展开全部

标题字段名称,指定为字符串或字符向量。姓名determines the type of the field, which determines valid values for theValue财产。如果您设置姓名[]或一个空字符串,然后Value[]

If this object is an instance of a subclass implementing a specific header field type, then that class enforces constraints on the姓名财产。

例子:'内容类型'

属性:

GetAccess
public
setAccess
public

标题场值,,,,specified as a string or any type valid for the姓名财产。

当您阅读此属性时,Value是一个字符串翅ting the value in the field.

When you set this property,Value是否可以根据该字段接受的任何类型姓名property and/or the class of this object. The result is converted to a string. If a field type has a default value, setValue到an empty string (''or细绳(''))。如果指定一个空的双,[],然后是请求消息sendandcomplete方法不会将此字段添加到消息中。

例子:'文本/html'

属性:

GetAccess
public
setAccess
public
Dependent
true

Methods

展开全部

例子

全部收缩

要创建一个内容类型标题字段,请使用Headerfield班级或ContentTypefield类构造函数。

当您使用Headerfield类构造函数,您指定姓名属性为'内容类型'。但是,如果您拼错了字段名称,则在服务器拒绝消息之前,您可能不会发现错误。一些服务器默默地忽略了未知的字段名称。

f1 = matlab.net.http.HeaderField('内容类型',,,,“文字/普通”);

使用ContentTypefield首选类构造函数,因为您无法拼写字段名称。

f2 = matlab.net.http.field.contenttypefield(“文字/普通”);

如果是Value属性是相同的,那么字段是相等的,无论您使用哪个构造函数。

F1 == F2
ans = 1

此示例显示了如何找到特定的标头字段Cache-Control在Mathworks.com的回应中。

发送消息Mathworks.com

request = matlab.net.http.RequestMessage; uri = matlab.net.URI('//www.tianjin-qmedu.com');response = send(request,uri);

搜索Cache-Control并显示值。

字段=响应。“缓存控制”);值= field.value
值=“ max-age = 14400”

Tips

  • Headerfieldconstructor creates fields of classHeaderfield。创建在matlab.net.http.fieldpackage, use the subclass constructor instead. For a list of subclasses, call theheaderfield.displaysubclasses方法。

    For example, thematlab.net.http.field.datefield子类创建日期标题字段。如果您使用Headerfieldclass to create a Date field, thedatefield班级解释并执行该值,即使Headerfield不是datefield。同样,如果将字段值转换为MATLABdatetimevalue, thedatefield。转变使用方法。

  • 如果是Headerfield构造函数拒绝姓名andValue参数,使用通用菲尔德class constructor instead.

在R2016b中引入